Skip to content

Commit 5f3775a

Browse files
committed
Initial Commit
0 parents  commit 5f3775a

7 files changed

+119
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
npm-debug.log
3+
node_modules

LICENSE.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2015 Antonio Scandurra
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# theme-flux package
2+
3+
This packages switches your theme to `one-light-ui`/`one-light-syntax` during the day, and automatically changes it to `one-dark-ui`/`one-dark-syntax` at night.

lib/theme-flux.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use babel';
2+
3+
import {minutesToMilliseconds} from './time-helpers'
4+
5+
export default {
6+
intervalId: null,
7+
wasDay: null,
8+
9+
activate() {
10+
let milliseconds = minutesToMilliseconds(this.getCheckIntervalInMinutes())
11+
this.intervalId = setInterval(this.changeTheme.bind(this), milliseconds)
12+
this.changeTheme()
13+
},
14+
15+
deactivate() {
16+
clearInterval(this.intervalId)
17+
this.intervalId = null
18+
},
19+
20+
changeTheme() {
21+
let isDay = this.isDay()
22+
if (isDay === this.wasDay) return
23+
24+
if (isDay) {
25+
atom.config.set('core.themes', ['one-light-ui', 'one-light-syntax'])
26+
} else {
27+
atom.config.set('core.themes', ['one-dark-ui', 'one-dark-syntax'])
28+
}
29+
30+
this.wasDay = isDay
31+
},
32+
33+
isDay() {
34+
let hours = new Date(Date.now()).getHours()
35+
return hours >= 7 && hours <= 17
36+
},
37+
38+
getCheckIntervalInMinutes() {
39+
return 15
40+
}
41+
};

lib/time-helpers.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use babel'
2+
3+
export function minutesToMilliseconds(minutes) {
4+
return minutes * 60 * 1000
5+
}

package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "theme-flux",
3+
"main": "./lib/theme-flux",
4+
"version": "0.0.0",
5+
"description": "A short description of your package",
6+
"keywords": [
7+
],
8+
"repository": "https://github.com/atom/theme-flux",
9+
"license": "MIT",
10+
"engines": {
11+
"atom": ">=1.0.0 <2.0.0"
12+
}
13+
}

spec/theme-flux-spec.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use babel'
2+
3+
import {minutesToMilliseconds} from '../lib/time-helpers'
4+
import ThemeFlux from '../lib/theme-flux'
5+
6+
describe('ThemeFlux', () => {
7+
beforeEach(() => {
8+
spyOn(Date, "now")
9+
window.setInterval = window.fakeSetInterval
10+
})
11+
12+
it('changes the theme to dark at night, and to light during the day', () => {
13+
atom.config.set('core.themes', ['', ''])
14+
Date.now.andReturn(new Date(1994, 4, 22, 23).getTime())
15+
ThemeFlux.activate()
16+
expect(atom.config.get('core.themes')).toEqual(['one-dark-ui', 'one-dark-syntax'])
17+
18+
Date.now.andReturn(new Date(1994, 4, 22, 10).getTime())
19+
advanceClock(minutesToMilliseconds(ThemeFlux.getCheckIntervalInMinutes()))
20+
expect(atom.config.get('core.themes')).toEqual(['one-light-ui', 'one-light-syntax'])
21+
22+
Date.now.andReturn(new Date(1994, 4, 22, 18).getTime())
23+
advanceClock(minutesToMilliseconds(ThemeFlux.getCheckIntervalInMinutes()))
24+
expect(atom.config.get('core.themes')).toEqual(['one-dark-ui', 'one-dark-syntax'])
25+
26+
Date.now.andReturn(new Date(1994, 4, 23, 5).getTime())
27+
advanceClock(minutesToMilliseconds(ThemeFlux.getCheckIntervalInMinutes()))
28+
expect(atom.config.get('core.themes')).toEqual(['one-dark-ui', 'one-dark-syntax'])
29+
30+
Date.now.andReturn(new Date(1994, 4, 23, 7).getTime())
31+
advanceClock(minutesToMilliseconds(ThemeFlux.getCheckIntervalInMinutes()))
32+
expect(atom.config.get('core.themes')).toEqual(['one-light-ui', 'one-light-syntax'])
33+
})
34+
})

0 commit comments

Comments
 (0)