-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
87 lines (73 loc) · 1.54 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const electron = require('electron');
const {app} = electron;
const {BrowserWindow, globalShortcut, Tray, Menu} = electron;
const path = require('path');
const iconPath = path.join(__dirname, 'icon.png');
let win;
let appIcon;
function createWindow() {
appIcon = new Tray(iconPath);
win = new BrowserWindow({
width: 400,
height: 600,
type: 'textured'
});
win.loadURL(`file://${__dirname}/index.html`);
globalShortcut.register('Control+A', () => {
if (win.isFocused()) {
win.blur();
} else {
win.show();
}
});
var contextMenu = Menu.buildFromTemplate([
{
label: 'Item1',
type: 'radio',
icon: iconPath
},
{
label: 'Item2',
submenu: [
{ label: 'submenu1' },
{ label: 'submenu2' }
]
},
{
label: 'Item3',
type: 'radio',
checked: true
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Command+I',
click: function() {
win.show();
}
},
{ label: 'Quit',
accelerator: 'Command+Q',
selector: 'terminate:'
}
]);
appIcon.setToolTip('This is my application.');
appIcon.setContextMenu(contextMenu);
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
globalShortcut.unregisterAll();
});
app.on('will-quit', () => {
if (process.platform !== 'darwin') {
app.quit();
}
globalShortcut.unregisterAll();
});
app.on('activate', () => {
if (win === null) {
createWindow();
}
});