forked from terkelg/ramme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tray.js
78 lines (69 loc) · 1.48 KB
/
tray.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
'use strict';
const path = require('path');
const electron = require('electron');
const app = electron.app;
const shell = electron.shell;
const Tray = electron.Tray;
const Menu = electron.Menu;
const trayIconDefault = path.join(__dirname, 'static/icon-18x18.png');
const trayIconWindows = path.join(__dirname, 'static/icon.ico');
let tray = null;
exports.create = win => {
if (process.platform === 'darwin' || tray) {
return;
}
let icon = trayIconDefault;
if (process.platform === 'win32') {
icon = trayIconWindows;
}
const toggleWin = () => {
if (process.platform === 'win32') {
if (win.isMinimized()) {
win.restore();
} else if (win.isVisible()) {
win.hide();
} else {
win.show();
}
} else {
win.isVisible() ? win.hide() : win.show();
}
};
// Create toolbar
tray = new Tray(icon);
const contextMenu = [{
label: 'Toggle',
click() {
toggleWin();
}
},
{
type: 'separator'
},
{
label: 'GitHub',
click() {
shell.openExternal('https://github.com/terkelg/ramme');
}
},
{
label: 'Issue',
click() {
shell.openExternal('https://github.com/terkelg/ramme/issues');
}
},
{
type: 'separator'
},
{
label: 'Quit',
click() {
app.quit();
}
}];
tray.setToolTip(`${app.getName()}`);
tray.setContextMenu(Menu.buildFromTemplate(contextMenu));
tray.on('click', function handleClicked () {
toggleWin();
});
};