Skip to content

Commit e106ab4

Browse files
committed
Show menu on only macOS
1 parent 6be505c commit e106ab4

1 file changed

Lines changed: 40 additions & 30 deletions

File tree

app/main.js

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,57 +24,67 @@ function createWindow () {
2424
shell.openExternal(url)
2525
})
2626

27-
const template = [
28-
{
27+
win.on('closed', () => win = null)
28+
29+
setupMenu()
30+
}
31+
32+
app.on('ready', createWindow)
33+
app.on('window-all-closed', () => {
34+
if (process.platform !== 'darwin') {
35+
app.quit()
36+
}
37+
})
38+
app.on('activate', () => {
39+
if (win === null) {
40+
createWindow()
41+
}
42+
})
43+
44+
function setupMenu () {
45+
const menus = []
46+
47+
if (process.platform === 'darwin') {
48+
menus.push({
2949
label: 'Application',
3050
submenu: [
31-
{ label: 'Quit', accelerator: 'Command+Q', click: () => { app.quit() } }
51+
{ role: 'quit' }
3252
]
33-
},
34-
{
53+
})
54+
55+
menus.push({
3556
label: 'Edit',
3657
submenu: [
37-
{ label: 'Undo', accelerator: 'CmdOrCtrl+Z', selector: 'undo:' },
38-
{ label: 'Redo', accelerator: 'Shift+CmdOrCtrl+Z', selector: 'redo:' },
58+
{ role: 'undo' },
59+
{ role: 'redo' },
3960
{ type: 'separator' },
40-
{ label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'cut:' },
41-
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
42-
{ label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:' },
43-
{ label: 'Select All', accelerator: 'CmdOrCtrl+A', selector: 'selectAll:' }
61+
{ role: 'cut' },
62+
{ role: 'copy' },
63+
{ role: 'paste' },
64+
{ role: 'selectall' }
4465
]
45-
}
46-
]
66+
})
67+
}
4768

4869
if (process.env.NODE_ENV === 'development') {
49-
template.push({
70+
menus.push({
5071
label: 'View',
5172
submenu: [
5273
{
5374
label: 'Reload',
5475
accelerator: 'Command+R',
55-
click: (_, activeWin) => activeWin.reload()
76+
click: () => win.reload()
5677
},
5778
{
5879
label: 'Toggle Developer Tools',
5980
accelerator: 'Alt+Command+I',
60-
click: (_, activeWin) => activeWin.toggleDevTools()
81+
click: () => win.toggleDevTools()
6182
},
6283
]
6384
})
6485
}
65-
Menu.setApplicationMenu(Menu.buildFromTemplate(template))
6686

67-
win.on('closed', () => win = null)
68-
}
69-
70-
app.on('ready', createWindow)
71-
app.on('window-all-closed', () => {
72-
if (process.platform !== 'darwin') {
73-
app.quit()
74-
}
75-
})
76-
app.on('activate', () => {
77-
if (win === null) {
78-
createWindow()
87+
if (menus.length > 0) {
88+
Menu.setApplicationMenu(Menu.buildFromTemplate(menus))
7989
}
80-
})
90+
}

0 commit comments

Comments
 (0)