-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
67 lines (55 loc) · 1.66 KB
/
main.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
const { app, Menu, Tray, nativeImage } = require('electron')
let path = require('path')
var fs = require('fs');
var text2png = require('text2png');
let appIcon = null
const options = {
color: 'white',
paddingTop: 2,
paddingBottom: 2,
font: '8px sans-serif',
borderWidth: 0,
//bgColor: 'black',
};
// For example, the code argument below might be the string `123456`
function updateTrayIconWithCode(code, tray) {
//fs.writeFileSync(path.join(__dirname, 'out.png'), text2png(code, options));
const img = nativeImage.createFromBuffer(text2png(code, options))
tray.setImage(img)
}
getTrend = (trend) => {
switch (trend) {
case "DoubleUp":
return "↑↑";
case "SingleUp":
return "↑";
case "FortyFiveUp":
return "↗";
case "Flat":
return "→";
case "FortyFiveDown":
return "↘";
case "SingleDown":
return "↓";
case "DoubleDown":
return "↓↓";
}
return ''
}
app.on('ready', () => {
const img = nativeImage.createFromBuffer(text2png('???', options))
appIcon = new Tray(img)
const contextMenu = Menu.buildFromTemplate([
{ label: 'Item1', type: 'radio' },
{ label: 'Item2', type: 'radio' }
])
// Make a change to the context menu
contextMenu.items[1].checked = false
// Call this again for Linux because we modified the context menu
appIcon.setContextMenu(contextMenu)
let total = 555
setInterval(() => {
let trendChar = getTrend('SingleDown');
return updateTrayIconWithCode((total++ % 600) + '', appIcon)
}, 1000);
})