Skip to content

Commit 0d797ce

Browse files
authored
Merge pull request #2658 from gregueiras/fixIssue2534
Fix issue2534
2 parents 5f56d3e + 4915c54 commit 0d797ce

File tree

6 files changed

+411
-14
lines changed

6 files changed

+411
-14
lines changed

browser/main/Main.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { store } from 'browser/main/store'
1616
import i18n from 'browser/lib/i18n'
1717
import { getLocales } from 'browser/lib/Languages'
1818
import applyShortcuts from 'browser/main/lib/shortcutManager'
19-
import uiThemes from 'browser/lib/ui-themes'
19+
import { chooseTheme, applyTheme } from 'browser/main/lib/ThemeManager'
2020
import { push } from 'connected-react-router'
2121

2222
const path = require('path')
@@ -148,11 +148,13 @@ class Main extends React.Component {
148148
componentDidMount() {
149149
const { dispatch, config } = this.props
150150

151-
if (uiThemes.some(theme => theme.name === config.ui.theme)) {
152-
document.body.setAttribute('data-theme', config.ui.theme)
153-
} else {
154-
document.body.setAttribute('data-theme', 'default')
155-
}
151+
this.refreshTheme = setInterval(() => {
152+
const conf = ConfigManager.get()
153+
chooseTheme(conf)
154+
}, 5 * 1000)
155+
156+
chooseTheme(config)
157+
applyTheme(config.ui.theme)
156158

157159
if (getLocales().indexOf(config.ui.language) !== -1) {
158160
i18n.setLocale(config.ui.language)
@@ -191,6 +193,7 @@ class Main extends React.Component {
191193
this.toggleMenuBarVisible.bind(this)
192194
)
193195
eventEmitter.off('dispatch:push', this.changeRoutePush.bind(this))
196+
clearInterval(this.refreshTheme)
194197
}
195198

196199
changeRoutePush(event, destination) {

browser/main/lib/ConfigManager.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ 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 uiThemes from 'browser/lib/ui-themes'
65

76
const OSX = global.process.platform === 'darwin'
87
const win = global.process.platform === 'win32'
@@ -47,6 +46,11 @@ export const DEFAULT_CONFIG = {
4746
ui: {
4847
language: 'en',
4948
theme: 'default',
49+
defaultTheme: 'default',
50+
enableScheduleTheme: false,
51+
scheduledTheme: 'monokai',
52+
scheduleStart: 1200,
53+
scheduleEnd: 360,
5054
showCopyNotification: true,
5155
disableDirectWrite: false,
5256
showScrollBar: true,
@@ -200,12 +204,6 @@ function set(updates) {
200204
if (!validate(newConfig)) throw new Error('INVALID CONFIG')
201205
_save(newConfig)
202206

203-
if (uiThemes.some(theme => theme.name === newConfig.ui.theme)) {
204-
document.body.setAttribute('data-theme', newConfig.ui.theme)
205-
} else {
206-
document.body.setAttribute('data-theme', 'default')
207-
}
208-
209207
i18n.setLocale(newConfig.ui.language)
210208

211209
let editorTheme = document.getElementById('editorTheme')

browser/main/lib/ThemeManager.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import ConfigManager from 'browser/main/lib/ConfigManager'
2+
3+
const saveChanges = newConfig => {
4+
ConfigManager.set(newConfig)
5+
}
6+
7+
const chooseTheme = config => {
8+
const { ui } = config
9+
if (!ui.enableScheduleTheme) {
10+
return
11+
}
12+
13+
const start = parseInt(ui.scheduleStart)
14+
const end = parseInt(ui.scheduleEnd)
15+
16+
const now = new Date()
17+
const minutes = now.getHours() * 60 + now.getMinutes()
18+
19+
const isEndAfterStart = end > start
20+
const isBetweenStartAndEnd = minutes >= start && minutes < end
21+
const isBetweenEndAndStart = minutes >= start || minutes < end
22+
23+
if (
24+
(isEndAfterStart && isBetweenStartAndEnd) ||
25+
(!isEndAfterStart && isBetweenEndAndStart)
26+
) {
27+
if (ui.theme !== ui.scheduledTheme) {
28+
ui.defaultTheme = ui.theme
29+
ui.theme = ui.scheduledTheme
30+
applyTheme(ui.theme)
31+
saveChanges(config)
32+
}
33+
} else {
34+
if (ui.theme !== ui.defaultTheme) {
35+
ui.theme = ui.defaultTheme
36+
applyTheme(ui.theme)
37+
saveChanges(config)
38+
}
39+
}
40+
}
41+
42+
const applyTheme = theme => {
43+
const supportedThemes = [
44+
'dark',
45+
'white',
46+
'solarized-dark',
47+
'monokai',
48+
'dracula'
49+
]
50+
if (supportedThemes.indexOf(theme) !== -1) {
51+
document.body.setAttribute('data-theme', theme)
52+
if (document.body.querySelector('.MarkdownPreview')) {
53+
document.body
54+
.querySelector('.MarkdownPreview')
55+
.contentDocument.body.setAttribute('data-theme', theme)
56+
}
57+
} else {
58+
document.body.setAttribute('data-theme', 'default')
59+
}
60+
}
61+
62+
module.exports = {
63+
chooseTheme,
64+
applyTheme
65+
}

browser/main/modals/PreferencesModal/ConfigTab.styl

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,109 @@
11
@import('./Tab')
22

3+
.container
4+
display flex
5+
flex-direction column
6+
align-items center
7+
justify-content center
8+
position relative
9+
margin-bottom 2em
10+
margin-left 2em
11+
12+
.box-minmax
13+
width 608px
14+
height 45px
15+
display flex
16+
justify-content space-between
17+
font-size $tab--button-font-size
18+
color $ui-text-color
19+
span first-child
20+
margin-top 18px
21+
padding-right 10px
22+
padding-left 10px
23+
padding-top 8px
24+
position relative
25+
border $ui-borderColor
26+
border-radius 5px
27+
background $ui-backgroundColor
28+
29+
div[id^="secondRow"]
30+
position absolute
31+
z-index 2
32+
left 0
33+
top 0
34+
margin-bottom -42px
35+
.rs-label
36+
margin-left -20px
37+
38+
div[id^="firstRow"]
39+
position absolute
40+
z-index 2
41+
left 0
42+
top 0
43+
margin-bottom -25px
44+
.rs-range
45+
&::-webkit-slider-thumb
46+
margin-top 0px
47+
transform rotate(180deg)
48+
.rs-label
49+
margin-bottom -85px
50+
margin-top 85px
51+
52+
53+
.rs-range
54+
margin-top 29px
55+
width 600px
56+
-webkit-appearance none
57+
&:focus
58+
outline black
59+
&::-webkit-slider-runnable-track
60+
width 100%
61+
height 0.1px
62+
cursor pointer
63+
box-shadow none
64+
background $ui-backgroundColor
65+
border-radius 0px
66+
border 0px solid #010101
67+
cursor none
68+
69+
&::-webkit-slider-thumb
70+
box-shadow none
71+
border 1px solid $ui-borderColor
72+
box-shadow 0px 10px 10px rgba(0, 0, 0, 0.25)
73+
height 32px
74+
width 32px
75+
border-radius 22px
76+
background white
77+
cursor pointer
78+
-webkit-appearance none
79+
margin-top -20px
80+
border-color $ui-default-button-backgroundColor
81+
height 32px
82+
border-top-left-radius 10%
83+
border-top-right-radius 10%
84+
85+
.rs-label
86+
position relative
87+
transform-origin center center
88+
display block
89+
background transparent
90+
border-radius none
91+
line-height 30px
92+
font-weight normal
93+
box-sizing border-box
94+
border none
95+
margin-bottom -5px
96+
margin-top -10px
97+
clear both
98+
float left
99+
height 17px
100+
margin-left -25px
101+
left attr(value)
102+
color $ui-text-color
103+
font-style normal
104+
font-weight normal
105+
line-height normal
106+
font-size $tab--button-font-size
3107
.root
4108
padding 15px
5109
margin-bottom 30px
@@ -175,6 +279,9 @@ body[data-theme="dark"]
175279
.group-section-control
176280
select, .group-section-control-input
177281
colorDarkControl()
282+
.rs-label
283+
color $ui-dark-text-color
284+
178285

179286
apply-theme(theme)
180287
body[data-theme={theme}]
@@ -205,6 +312,8 @@ apply-theme(theme)
205312
.group-section-control
206313
select, .group-section-control-input
207314
colorThemedControl(theme)
315+
.rs-label
316+
color get-theme-var(theme, 'text-color')
208317

209318
for theme in 'solarized-dark' 'dracula'
210319
apply-theme(theme)

0 commit comments

Comments
 (0)