1
0
mirror of https://github.com/BoostIo/Boostnote synced 2026-01-04 12:39:17 +00:00

ThemeManager Created

This commit is contained in:
gregueiras
2018-11-28 12:04:33 +00:00
parent 8be0ea64a5
commit f38fef23a0
4 changed files with 62 additions and 23 deletions

View File

@@ -2,6 +2,7 @@ import _ from 'lodash'
import RcParser from 'browser/lib/RcParser'
import i18n from 'browser/lib/i18n'
import ee from 'browser/main/lib/eventEmitter'
import theme from 'browser/main/lib/ThemeManager'
const OSX = global.process.platform === 'darwin'
const win = global.process.platform === 'win32'
@@ -30,8 +31,9 @@ export const DEFAULT_CONFIG = {
ui: {
language: 'en',
theme: 'default',
defaultTheme: 'default',
enableScheduleTheme: false,
scheduledTheme: 'Monokai',
scheduledTheme: 'monokai',
scheduleStart: 1200,
scheduleEnd: 360,
showCopyNotification: true,
@@ -149,19 +151,8 @@ function set (updates) {
if (!validate(newConfig)) throw new Error('INVALID CONFIG')
_save(newConfig)
if (newConfig.ui.theme === 'dark') {
document.body.setAttribute('data-theme', 'dark')
} else if (newConfig.ui.theme === 'white') {
document.body.setAttribute('data-theme', 'white')
} else if (newConfig.ui.theme === 'solarized-dark') {
document.body.setAttribute('data-theme', 'solarized-dark')
} else if (newConfig.ui.theme === 'monokai') {
document.body.setAttribute('data-theme', 'monokai')
} else if (newConfig.ui.theme === 'dracula') {
document.body.setAttribute('data-theme', 'dracula')
} else {
document.body.setAttribute('data-theme', 'default')
}
theme.choose(newConfig.ui)
theme.apply(newConfig.ui.theme)
i18n.setLocale(newConfig.ui.language)

View File

@@ -0,0 +1,49 @@
function choose (ui) {
console.log(ui.enableScheduleTheme)
if (ui.enableScheduleTheme !== 'on') {
return
}
const start = parseInt(ui.scheduleStart)
const end = parseInt(ui.scheduleEnd)
const now = new Date()
const minutes = now.getHours() * 60 + now.getMinutes()
console.log(ui.scheduleStart, minutes, ui.scheduleEnd)
if ((end > start && minutes >= start && minutes <= end) ||
(start > end && (minutes >= start || minutes <= end))) {
console.log('SC', ui.theme, ui.scheduledTheme)
if (ui.theme !== ui.scheduledTheme) {
ui.defaultTheme = ui.theme
ui.theme = ui.scheduledTheme
apply(ui.theme)
}
console.log(ui.defaultTheme, ui.theme)
} else {
console.log('TH', ui.theme, ui.defaultTheme)
if (ui.theme !== ui.defaultTheme) {
ui.theme = ui.defaultTheme
apply(ui.theme)
}
console.log(ui.theme)
}
}
function apply (theme) {
console.log('Apply ', theme)
const supportedThemes = ['dark', 'white', 'solarized-dark', 'monokai', 'dracula']
if (supportedThemes.indexOf(theme) !== -1) {
document.body.setAttribute('data-theme', theme)
} else {
document.body.setAttribute('data-theme', 'default')
}
}
export default {
choose,
apply
}