-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
61 lines (52 loc) · 1.15 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
60
61
/***
* 主进程
*/
const path = require('path');
const E = require('electron');
const { app, BrowserWindow, Menu, Tray } = E;
let mainWindow, appIcon;
app.dock.hide();
app.on('ready', init);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
})
app.on('activate', () => {
if (mainWindow = null) {
init();
}
})
function init() {
var iconPath = path.join(__dirname, 'image/[email protected]');
appIcon = new Tray(iconPath);
appIcon.setToolTip('Snooker For Mac');
appIcon.on('click', () => {
if (!mainWindow) {
createWindow();
} else {
mainWindow.close();
mainWindow = null;
}
});
app.on('browser-window-blur', () => {
mainWindow.close();
mainWindow = null;
})
}
function createWindow() {
const width = 300, height = 500;
mainWindow = new BrowserWindow({
x: appIcon.getBounds().x - width / 2 + 16,
y: appIcon.getBounds().y,
width: width,
height: height,
resizable: false,
frame: false,
backgroundColor: '#ffffff'
});
mainWindow.loadURL(`file://${__dirname}/index.html`);
mainWindow.on('close', () => {
mainWindow = null;
});
}