diff --git a/browser/main/Main.js b/browser/main/Main.js index fa632eef..a3bdc28f 100644 --- a/browser/main/Main.js +++ b/browser/main/Main.js @@ -17,7 +17,7 @@ import store from 'browser/main/store' import i18n from 'browser/lib/i18n' import { getLocales } from 'browser/lib/Languages' import applyShortcuts from 'browser/main/lib/shortcutManager' -import theme from 'browser/main/lib/ThemeManager' +import {chooseTheme, applyTheme} from 'browser/main/lib/ThemeManager' const path = require('path') const electron = require('electron') const { remote } = electron @@ -142,11 +142,11 @@ class Main extends React.Component { const { dispatch, config } = this.props this.refreshTheme = setInterval(() => { - theme.choose(ConfigManager.get().ui) + chooseTheme(ConfigManager.get().ui) }, 5 * 1000) - theme.choose(config.ui) - theme.apply(config.ui.theme) + chooseTheme(config.ui) + applyTheme(config.ui.theme) if (getLocales().indexOf(config.ui.language) !== -1) { i18n.setLocale(config.ui.language) diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 40d0771e..f39eb32e 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -2,8 +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' - +import {chooseTheme, applyTheme} from 'browser/main/lib/ThemeManager' const OSX = global.process.platform === 'darwin' const win = global.process.platform === 'win32' const electron = require('electron') @@ -151,8 +150,8 @@ function set (updates) { if (!validate(newConfig)) throw new Error('INVALID CONFIG') _save(newConfig) - theme.choose(newConfig.ui) - theme.apply(newConfig.ui.theme) + chooseTheme(newConfig.ui) + applyTheme(newConfig.ui.theme) i18n.setLocale(newConfig.ui.language) diff --git a/browser/main/lib/ThemeManager.js b/browser/main/lib/ThemeManager.js index 0cab6c2d..a6be2f82 100644 --- a/browser/main/lib/ThemeManager.js +++ b/browser/main/lib/ThemeManager.js @@ -1,5 +1,4 @@ -function choose (ui) { - console.log(ui.enableScheduleTheme) +const chooseTheme = (ui) => { if (!ui.enableScheduleTheme) { return } @@ -10,31 +9,25 @@ function choose (ui) { const now = new Date() const minutes = now.getHours() * 60 + now.getMinutes() - console.log(ui.scheduleStart, minutes, ui.scheduleEnd) + const isEndAfterStart = end > start + const isBetweenStartAndEnd = minutes >= start && minutes <= end + const isBetweenEndAndStart = (minutes >= start || minutes <= end) - if ((end > start && minutes >= start && minutes <= end) || - (start > end && (minutes >= start || minutes <= end))) { - console.log('SC', ui.theme, ui.scheduledTheme) + if ((isEndAfterStart && isBetweenStartAndEnd) || (!isEndAfterStart && isBetweenEndAndStart)) { if (ui.theme !== ui.scheduledTheme) { ui.defaultTheme = ui.theme ui.theme = ui.scheduledTheme - apply(ui.theme) + applyTheme(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) + applyTheme(ui.theme) } - - console.log(ui.theme) } } -function apply (theme) { - console.log('Apply ', theme) +const applyTheme = (theme) => { const supportedThemes = ['dark', 'white', 'solarized-dark', 'monokai', 'dracula'] if (supportedThemes.indexOf(theme) !== -1) { document.body.setAttribute('data-theme', theme) @@ -43,7 +36,7 @@ function apply (theme) { } } -export default { - choose, - apply +module.exports = { + chooseTheme, + applyTheme }