Skip to content

Commit cd53a65

Browse files
committed
Code Style Improvements
1 parent 8b54f5a commit cd53a65

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

browser/main/Main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import store from 'browser/main/store'
1717
import i18n from 'browser/lib/i18n'
1818
import { getLocales } from 'browser/lib/Languages'
1919
import applyShortcuts from 'browser/main/lib/shortcutManager'
20-
import theme from 'browser/main/lib/ThemeManager'
20+
import {chooseTheme, applyTheme} from 'browser/main/lib/ThemeManager'
2121
const path = require('path')
2222
const electron = require('electron')
2323
const { remote } = electron
@@ -142,11 +142,11 @@ class Main extends React.Component {
142142
const { dispatch, config } = this.props
143143

144144
this.refreshTheme = setInterval(() => {
145-
theme.choose(ConfigManager.get().ui)
145+
chooseTheme(ConfigManager.get().ui)
146146
}, 5 * 1000)
147147

148-
theme.choose(config.ui)
149-
theme.apply(config.ui.theme)
148+
chooseTheme(config.ui)
149+
applyTheme(config.ui.theme)
150150

151151
if (getLocales().indexOf(config.ui.language) !== -1) {
152152
i18n.setLocale(config.ui.language)

browser/main/lib/ConfigManager.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import _ from 'lodash'
22
import RcParser from 'browser/lib/RcParser'
33
import i18n from 'browser/lib/i18n'
44
import ee from 'browser/main/lib/eventEmitter'
5-
import theme from 'browser/main/lib/ThemeManager'
6-
5+
import {chooseTheme, applyTheme} from 'browser/main/lib/ThemeManager'
76
const OSX = global.process.platform === 'darwin'
87
const win = global.process.platform === 'win32'
98
const electron = require('electron')
@@ -151,8 +150,8 @@ function set (updates) {
151150
if (!validate(newConfig)) throw new Error('INVALID CONFIG')
152151
_save(newConfig)
153152

154-
theme.choose(newConfig.ui)
155-
theme.apply(newConfig.ui.theme)
153+
chooseTheme(newConfig.ui)
154+
applyTheme(newConfig.ui.theme)
156155

157156
i18n.setLocale(newConfig.ui.language)
158157

browser/main/lib/ThemeManager.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
function choose (ui) {
2-
console.log(ui.enableScheduleTheme)
1+
const chooseTheme = (ui) => {
32
if (!ui.enableScheduleTheme) {
43
return
54
}
@@ -10,31 +9,25 @@ function choose (ui) {
109
const now = new Date()
1110
const minutes = now.getHours() * 60 + now.getMinutes()
1211

13-
console.log(ui.scheduleStart, minutes, ui.scheduleEnd)
12+
const isEndAfterStart = end > start
13+
const isBetweenStartAndEnd = minutes >= start && minutes <= end
14+
const isBetweenEndAndStart = (minutes >= start || minutes <= end)
1415

15-
if ((end > start && minutes >= start && minutes <= end) ||
16-
(start > end && (minutes >= start || minutes <= end))) {
17-
console.log('SC', ui.theme, ui.scheduledTheme)
16+
if ((isEndAfterStart && isBetweenStartAndEnd) || (!isEndAfterStart && isBetweenEndAndStart)) {
1817
if (ui.theme !== ui.scheduledTheme) {
1918
ui.defaultTheme = ui.theme
2019
ui.theme = ui.scheduledTheme
21-
apply(ui.theme)
20+
applyTheme(ui.theme)
2221
}
23-
24-
console.log(ui.defaultTheme, ui.theme)
2522
} else {
26-
console.log('TH', ui.theme, ui.defaultTheme)
2723
if (ui.theme !== ui.defaultTheme) {
2824
ui.theme = ui.defaultTheme
29-
apply(ui.theme)
25+
applyTheme(ui.theme)
3026
}
31-
32-
console.log(ui.theme)
3327
}
3428
}
3529

36-
function apply (theme) {
37-
console.log('Apply ', theme)
30+
const applyTheme = (theme) => {
3831
const supportedThemes = ['dark', 'white', 'solarized-dark', 'monokai', 'dracula']
3932
if (supportedThemes.indexOf(theme) !== -1) {
4033
document.body.setAttribute('data-theme', theme)
@@ -43,7 +36,7 @@ function apply (theme) {
4336
}
4437
}
4538

46-
export default {
47-
choose,
48-
apply
39+
module.exports = {
40+
chooseTheme,
41+
applyTheme
4942
}

0 commit comments

Comments
 (0)