/
tray.js
38 lines (32 loc) · 969 Bytes
/
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
import path from 'path';
import electron from 'electron';
const app = electron.app;
let tray = null;
const create = win => {
if (tray) return;
const toggleWin = () => win.isVisible() ? win.hide() : win.show();
const contextMenu = electron.Menu.buildFromTemplate([
{
role: 'quit',
},
]);
tray = new electron.Tray(path.join(__dirname, '../src/assets/icons/menubarTemplate.png'));
// Disabling highlight mode makes toggling more reliable ¯\_(ツ)_/¯
// https://github.com/electron/electron/issues/1825
tray.setHighlightMode(false);
tray.setToolTip(`${app.getName()}`);
tray.on('click', e => {
// Not sure why right click event doesn't work for me so doing manually
if (e.ctrlKey) {
tray.popUpContextMenu(contextMenu);
} else {
toggleWin();
}
});
tray.on('right-click', () => tray.popUpContextMenu(contextMenu));
tray.on('double-click', () => toggleWin());
return tray;
};
export {
create,
};