-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.js
executable file
·79 lines (70 loc) · 1.89 KB
/
menu.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
const {app, Menu} = require('electron');
const electron = require('electron');
const url = require('url');
const path = require('path');
const BrowserWindow = electron.BrowserWindow;
const template = [
{
label: app.getName(),
submenu: [
{
label: 'Preferences...',
accelerator: process.platform === 'darwin' ? 'Command+,' : 'Ctrl+,',
click: openPreferences
},
{
role: 'quit'
},
{
role: 'close'
},
{
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
click(item, focusedWindow) {
if (focusedWindow) focusedWindow.reload();
}
},
{
label: 'Toggle Dev Tools',
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
click(item, focusedWindow) {
if (focusedWindow) focusedWindow.webContents.toggleDevTools();
}
}
]
}
]
let preferencesWindow;
function openPreferences() {
if (preferencesWindow == null) {
preferencesWindow = new BrowserWindow({
show: false,
width: 387,
height: 405,
x: 100,
y: 100,
});
// preferences always on top because the main window is also always on top and would block preferences windows without this
preferencesWindow.setAlwaysOnTop(true);
// gracefully show the preferences window
preferencesWindow.once('ready-to-show', () => {
preferencesWindow.show();
});
// preferencesWindow.webContents.openDevTools();
preferencesWindow.on('closed', () => {
preferencesWindow = null;
});
}
preferencesWindow.loadURL(url.format({
pathname: path.join(__dirname, './preferences/preferences.html'),
protocol: 'file:',
slashes: true,
}))
}
const menu = Menu.buildFromTemplate(template);
module.exports = {
menu: menu,
preferencesWindow: preferencesWindow,
openPreferences: openPreferences,
};