-
Notifications
You must be signed in to change notification settings - Fork 1
/
menubar.js
58 lines (47 loc) · 1.75 KB
/
menubar.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
(function() {
const {app, BrowserWindow, Tray, Menu} = require('electron');
const path = require('path');
class MenuBar {
constructor(menuTemplate, optionMenuTemplate) {
this.animateSpeed = 80;
this.tray = new Tray(path.join(__dirname, 'img/logo-dim-iconTemplate.png'));
this.tray.setToolTip('AirSonos');
this.tray.on('click', event => {
if (event.altKey) {
this.tray.popUpContextMenu(this.trayMenuOption);
} else {
this.tray.popUpContextMenu(this.trayMenu);
}
});
}
setMenuTemplates(templates) {
this.trayMenu = Menu.buildFromTemplate(templates[0]);
this.trayMenuOption = Menu.buildFromTemplate(templates[1]);
}
animatieIcon() {
var i = 0;
var j = 1;
this.animationInterval = setInterval(() => {
if (i < 0 || i > 12) {
j *= -1;
i += j;
}
this.tray.setImage(path.join(__dirname, `img/animations/logo${i}-iconTemplate.png`));
i += j;
}, this.animateSpeed);
}
enableIcon() {
if(this.animationInterval) {
clearInterval(this.animationInterval);
}
this.tray.setImage(path.join(__dirname, `img/logo-iconTemplate@2x.png`));
}
disableIcon() {
if(this.animationInterval) {
clearInterval(this.animationInterval);
}
this.tray.setImage(path.join(__dirname, `img/logo-dim-iconTemplate@2x.png`));
}
}
module.exports = MenuBar;
})();