-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
59 lines (53 loc) · 1.41 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
const { app, Menu, Tray, dialog, globalShortcut } = require("electron");
const path = require("path");
const GestureService = require("./GestureService");
let service, tray;
const trayUrls = [
path.join(__dirname, "./assets/images/app.ico"),
path.join(__dirname, "./assets/images/app-gray.ico"),
];
let trayUrl = trayUrls[0];
const menuTemplate = [
{
id: "toggle",
label: "暂停",
click: () => app.toggle(),
},
{
label: "退出",
click: () => app.quit(),
},
];
app.toggle = () => {
if (!service || !tray) {
return console.error("服务未启动");
}
if (app.isActive) {
service.pause();
menuTemplate[0].label = "激活";
trayUrl = trayUrls[1];
app.isActive = false;
} else {
service.active();
menuTemplate[0].label = "暂停";
trayUrl = trayUrls[0];
app.isActive = true;
}
tray.setImage(trayUrl);
tray.setContextMenu(Menu.buildFromTemplate(menuTemplate));
};
app.on("ready", () => {
service = new GestureService();
tray = new Tray(trayUrl);
tray.setToolTip("PointGesture");
tray.setContextMenu(Menu.buildFromTemplate(menuTemplate));
service.start();
globalShortcut.register("Shift+Alt+P", function () {
app.toggle();
});
app.isActive = true;
});
app.on("will-quit", () => {
service.stop();
globalShortcut.unregisterAll();
});