-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSystemTray.js
119 lines (98 loc) · 2.16 KB
/
SystemTray.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"use strict";
const electron = require("electron");
const MenuItems = {
SECRET: "SECRET",
OPEN: "OPEN",
CHECK_UPDATE: "CHECK_UPDATE",
QUIT: "QUIT"
};
let tray = null,
options,
menuItems,
contextMenu,
hasInit = (exports.hasInit = false);
function init(_options) {
if (hasInit) {
console.warn("systemTray: Has already init! Cancelling init.");
return;
}
exports.hasInit = hasInit = true;
options = _options;
menuItems = {};
contextMenu = [];
initializeMenuItems();
buildContextMenu();
}
function displayHowToCloseHint() {
if (tray == null) {
return;
}
const balloonMessage =
"Hi! Infinty will run in the background to keep you in touch with your friends." +
" You can right-click here to quit.";
tray.displayBalloon({
title: "Infinty",
content: balloonMessage
});
}
function initializeMenuItems() {
const { onTrayClicked, onCheckForUpdates, onQuit } = options;
menuItems[MenuItems.SECRET] = {
label: `Top Secret Control Panel`,
enabled: false
};
menuItems[MenuItems.OPEN] = {
label: `Open Infinty`,
type: "normal",
visible: process.platform === "linux",
click: onTrayClicked
};
menuItems[MenuItems.CHECK_UPDATE] = {
label: "Check for Updates...",
type: "normal",
visible: process.platform !== "darwin",
click: onCheckForUpdates
};
menuItems[MenuItems.QUIT] = {
label: `Quit Infinty`,
type: "normal",
visible: true,
click: onQuit
};
}
function buildContextMenu() {
const separator = { type: "separator" };
contextMenu = [
menuItems[MenuItems.SECRET],
separator,
menuItems[MenuItems.OPEN],
menuItems[MenuItems.CHECK_UPDATE],
separator,
menuItems[MenuItems.QUIT]
];
}
function setContextMenu() {
tray != null &&
tray.setContextMenu(electron.Menu.buildFromTemplate(contextMenu));
}
function show() {
if (tray != null) return;
tray = new electron.Tray(__dirname + "./assets/tray.png");
tray.setToolTip("Infinty");
setContextMenu();
tray.on("double-click", options.onTrayDoubleClicked);
}
function hide() {
if (tray == null) {
return;
}
tray.destroy();
tray = null;
}
module.exports = {
hasInit: undefined,
init: init,
show: show,
displayHowToCloseHint: displayHowToCloseHint,
tray: tray
};