-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
105 lines (94 loc) · 2.25 KB
/
index.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
const { app, BrowserWindow, Tray, ipcMain, Menu } = require("electron");
const Positioner = require("electron-positioner");
require("@electron/remote/main").initialize();
/**
* @type BrowserWindow
*/
let window;
/**
* @type Tray
*/
let tray;
let visible = false;
/**
* Based on code from https://github.com/maxogden/menubar/blob/master/src/util/getWindowPosition.ts
* @param {Electron.BrowserWindow} _window
* @param {Electron.Rectangle} _bounds
*/
const getPosition = (_window, _bounds) => {
const positioner = new Positioner(_window);
switch (process.platform) {
case "darwin":
return positioner.move("trayCenter", _bounds);
case "linux":
return positioner.move("topRight");
default:
return positioner.move("bottomRight");
}
};
app.on("ready", () => {
if (app.dock) {
app.dock.hide();
}
window = new BrowserWindow({
width: 300,
height: 500,
frame: false,
show: false,
skipTaskbar: true,
transparent: true,
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
enableRemoteModule: true,
},
resizable: false,
});
window.on("hide", () => {
visible = false;
});
window.loadURL(`file://${__dirname}/dist/index.html`);
window.on("blur", () => {
window.hide();
});
tray = new Tray(`${__dirname}/img/${process.platform == "darwin" ? "ZhongTemplate" : "Zhong"}.png`);
tray.setIgnoreDoubleClickEvents(true);
tray.on("click", () => {
if (!visible) {
getPosition(window, tray.getBounds());
window.show();
visible = true;
} else {
window.hide();
}
});
tray.on("right-click", () => {
tray.popUpContextMenu(
Menu.buildFromTemplate([
{
label: "Quit",
click() {
app.quit();
},
accelerator: "CommandOrControl+Q",
},
])
);
});
ipcMain.on("alert", () => {
const done = new BrowserWindow({
width: 300,
height: 300,
frame: false,
transparent: true,
skipTaskbar: true,
alwaysOnTop: true,
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
},
resizable: false,
});
done.loadURL(`file://${__dirname}/dist/done.html`);
});
});