mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-19 20:51:42 +00:00
ThemeManager Created
This commit is contained in:
@@ -17,6 +17,7 @@ import store from 'browser/main/store'
|
|||||||
import i18n from 'browser/lib/i18n'
|
import i18n from 'browser/lib/i18n'
|
||||||
import { getLocales } from 'browser/lib/Languages'
|
import { getLocales } from 'browser/lib/Languages'
|
||||||
import applyShortcuts from 'browser/main/lib/shortcutManager'
|
import applyShortcuts from 'browser/main/lib/shortcutManager'
|
||||||
|
import theme from 'browser/main/lib/ThemeManager'
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const { remote } = electron
|
const { remote } = electron
|
||||||
@@ -140,13 +141,12 @@ class Main extends React.Component {
|
|||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const { dispatch, config } = this.props
|
const { dispatch, config } = this.props
|
||||||
|
|
||||||
const supportedThemes = ['dark', 'white', 'solarized-dark', 'monokai', 'dracula']
|
this.refreshTheme = setInterval(() => {
|
||||||
|
theme.choose(ConfigManager.get().ui)
|
||||||
|
}, 5 * 1000)
|
||||||
|
|
||||||
if (supportedThemes.indexOf(config.ui.theme) !== -1) {
|
theme.choose(config.ui)
|
||||||
document.body.setAttribute('data-theme', config.ui.theme)
|
theme.apply(config.ui.theme)
|
||||||
} else {
|
|
||||||
document.body.setAttribute('data-theme', 'default')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getLocales().indexOf(config.ui.language) !== -1) {
|
if (getLocales().indexOf(config.ui.language) !== -1) {
|
||||||
i18n.setLocale(config.ui.language)
|
i18n.setLocale(config.ui.language)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import _ from 'lodash'
|
|||||||
import RcParser from 'browser/lib/RcParser'
|
import RcParser from 'browser/lib/RcParser'
|
||||||
import i18n from 'browser/lib/i18n'
|
import i18n from 'browser/lib/i18n'
|
||||||
import ee from 'browser/main/lib/eventEmitter'
|
import ee from 'browser/main/lib/eventEmitter'
|
||||||
|
import theme from 'browser/main/lib/ThemeManager'
|
||||||
|
|
||||||
const OSX = global.process.platform === 'darwin'
|
const OSX = global.process.platform === 'darwin'
|
||||||
const win = global.process.platform === 'win32'
|
const win = global.process.platform === 'win32'
|
||||||
@@ -30,8 +31,9 @@ export const DEFAULT_CONFIG = {
|
|||||||
ui: {
|
ui: {
|
||||||
language: 'en',
|
language: 'en',
|
||||||
theme: 'default',
|
theme: 'default',
|
||||||
|
defaultTheme: 'default',
|
||||||
enableScheduleTheme: false,
|
enableScheduleTheme: false,
|
||||||
scheduledTheme: 'Monokai',
|
scheduledTheme: 'monokai',
|
||||||
scheduleStart: 1200,
|
scheduleStart: 1200,
|
||||||
scheduleEnd: 360,
|
scheduleEnd: 360,
|
||||||
showCopyNotification: true,
|
showCopyNotification: true,
|
||||||
@@ -149,19 +151,8 @@ function set (updates) {
|
|||||||
if (!validate(newConfig)) throw new Error('INVALID CONFIG')
|
if (!validate(newConfig)) throw new Error('INVALID CONFIG')
|
||||||
_save(newConfig)
|
_save(newConfig)
|
||||||
|
|
||||||
if (newConfig.ui.theme === 'dark') {
|
theme.choose(newConfig.ui)
|
||||||
document.body.setAttribute('data-theme', 'dark')
|
theme.apply(newConfig.ui.theme)
|
||||||
} 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')
|
|
||||||
}
|
|
||||||
|
|
||||||
i18n.setLocale(newConfig.ui.language)
|
i18n.setLocale(newConfig.ui.language)
|
||||||
|
|
||||||
|
|||||||
49
browser/main/lib/ThemeManager.js
Normal file
49
browser/main/lib/ThemeManager.js
Normal 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
|
||||||
|
}
|
||||||
@@ -68,6 +68,7 @@ class UiTab extends React.Component {
|
|||||||
const newConfig = {
|
const newConfig = {
|
||||||
ui: {
|
ui: {
|
||||||
theme: this.refs.uiTheme.value,
|
theme: this.refs.uiTheme.value,
|
||||||
|
defaultTheme: this.refs.uiTheme.value,
|
||||||
enableScheduleTheme: this.refs.enableScheduleTheme.value,
|
enableScheduleTheme: this.refs.enableScheduleTheme.value,
|
||||||
scheduledTheme: this.refs.uiScheduledTheme.value,
|
scheduledTheme: this.refs.uiScheduledTheme.value,
|
||||||
scheduleStart: this.refs.scheduleStart.value,
|
scheduleStart: this.refs.scheduleStart.value,
|
||||||
@@ -203,8 +204,6 @@ class UiTab extends React.Component {
|
|||||||
|
|
||||||
if (e) {
|
if (e) {
|
||||||
this.handleUIChange(e)
|
this.handleUIChange(e)
|
||||||
} else {
|
|
||||||
console.log('HEY')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +230,7 @@ class UiTab extends React.Component {
|
|||||||
{i18n.__('Interface Theme')}
|
{i18n.__('Interface Theme')}
|
||||||
</div>
|
</div>
|
||||||
<div styleName='group-section-control'>
|
<div styleName='group-section-control'>
|
||||||
<select value={config.ui.theme}
|
<select value={config.ui.defaultTheme}
|
||||||
onChange={(e) => this.handleUIChange(e)}
|
onChange={(e) => this.handleUIChange(e)}
|
||||||
ref='uiTheme'
|
ref='uiTheme'
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user