forked from ungoldman/hi8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (77 loc) · 1.86 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { app, Menu, Tray } = require('electron')
const path = require('path')
const bg = require('himawari-bg')
const pkg = require('./package.json')
const second = 1000
const minute = second * 60
let tray = null
let timer = null
let shouldQuit = false
shouldQuit = app.makeSingleInstance((argv, wd) => {
console.log('Second app instance opened, but was prevented:', argv, wd)
})
if (shouldQuit) app.quit()
else app.on('ready', ready)
function ready () {
if (app.dock) app.dock.hide()
const iconPath = path.join(__dirname, 'assets', 'Icon-Template.png')
tray = new Tray(iconPath)
const contextMenu = Menu.buildFromTemplate([
{
label: `hi8 v${pkg.version}`,
enabled: false
},
{ type: 'separator' },
{
label: 'Update Desktop',
submenu: [
{
label: 'Now',
click: update
},
{ type: 'separator' },
{
label: 'Every 10 minutes',
type: 'radio',
click: update,
checked: true
},
{
label: 'Every hour',
type: 'radio',
click: update
},
{
label: 'Off',
type: 'radio',
click: update
}
]
},
{ type: 'separator' },
{
label: 'Quit',
click () { app.quit() }
}
])
tray.setToolTip('hi8')
tray.setContextMenu(contextMenu)
setBackground()
resetTimer(minute * 10)
}
function update ({ label }) {
switch (label) {
case 'Now': setBackground(); break
case 'Every 10 minutes': resetTimer(minute * 10); break
case 'Every hour': resetTimer(minute * 60); break
default: resetTimer()
}
}
function resetTimer (ms) {
clearInterval(timer)
if (ms) timer = setInterval(setBackground, ms)
}
function setBackground () {
let outfile = path.join(app.getPath('pictures'), 'Himawari-8', `${Date.now()}.jpg`)
bg({ outfile })
}