1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Code Style Improvements

This commit is contained in:
gregueiras
2018-11-29 13:58:15 +00:00
parent 8b54f5aa69
commit cd53a65c14
3 changed files with 18 additions and 26 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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
}