Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
fileMenu
/ viewMenu
/ appMenu
roles
- Loading branch information
Showing
6 changed files
with
275 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,168 +1,47 @@ | ||
const { shell, Menu } = require('electron') | ||
const isMac = process.platform === 'darwin' | ||
|
||
const setDefaultApplicationMenu = () => { | ||
if (Menu.getApplicationMenu()) return | ||
|
||
const template = [ | ||
{ | ||
label: 'Edit', | ||
submenu: [ | ||
{ | ||
role: 'undo' | ||
}, | ||
{ | ||
role: 'redo' | ||
}, | ||
{ | ||
type: 'separator' | ||
}, | ||
{ | ||
role: 'cut' | ||
}, | ||
{ | ||
role: 'copy' | ||
}, | ||
{ | ||
role: 'paste' | ||
}, | ||
{ | ||
role: 'pasteandmatchstyle' | ||
}, | ||
{ | ||
role: 'delete' | ||
}, | ||
{ | ||
role: 'selectall' | ||
module.exports = () => { | ||
const helpMenu = { | ||
role: 'help', | ||
submenu: [ | ||
{ | ||
label: 'Learn More', | ||
click () { | ||
shell.openExternal('https://electronjs.org') | ||
} | ||
] | ||
}, | ||
{ | ||
label: 'View', | ||
submenu: [ | ||
{ | ||
role: 'reload' | ||
}, | ||
{ | ||
role: 'forcereload' | ||
}, | ||
{ | ||
role: 'toggledevtools' | ||
}, | ||
{ | ||
type: 'separator' | ||
}, | ||
{ | ||
role: 'resetzoom' | ||
}, | ||
{ | ||
role: 'zoomin' | ||
}, | ||
{ | ||
role: 'zoomout' | ||
}, | ||
{ | ||
type: 'separator' | ||
}, | ||
{ | ||
role: 'togglefullscreen' | ||
}, | ||
{ | ||
label: 'Documentation', | ||
click () { | ||
shell.openExternal( | ||
`https://github.com/electron/electron/tree/v${process.versions.electron}/docs#readme` | ||
) | ||
} | ||
] | ||
}, | ||
{ | ||
role: 'windowMenu' | ||
}, | ||
{ | ||
role: 'help', | ||
submenu: [ | ||
{ | ||
label: 'Learn More', | ||
click () { | ||
shell.openExternal('https://electronjs.org') | ||
} | ||
}, | ||
{ | ||
label: 'Documentation', | ||
click () { | ||
shell.openExternal( | ||
`https://github.com/electron/electron/tree/v${process.versions.electron}/docs#readme` | ||
) | ||
} | ||
}, | ||
{ | ||
label: 'Community Discussions', | ||
click () { | ||
shell.openExternal('https://discuss.atom.io/c/electron') | ||
} | ||
}, | ||
{ | ||
label: 'Search Issues', | ||
click () { | ||
shell.openExternal('https://github.com/electron/electron/issues') | ||
} | ||
} | ||
] | ||
} | ||
] | ||
|
||
if (process.platform === 'darwin') { | ||
template.unshift({ | ||
label: 'Electron', | ||
submenu: [ | ||
{ | ||
role: 'about' | ||
}, | ||
{ | ||
type: 'separator' | ||
}, | ||
{ | ||
role: 'services' | ||
}, | ||
{ | ||
type: 'separator' | ||
}, | ||
{ | ||
role: 'hide' | ||
}, | ||
{ | ||
role: 'hideothers' | ||
}, | ||
{ | ||
role: 'unhide' | ||
}, | ||
{ | ||
type: 'separator' | ||
}, | ||
{ | ||
role: 'quit' | ||
}, | ||
{ | ||
label: 'Community Discussions', | ||
click () { | ||
shell.openExternal('https://discuss.atom.io/c/electron') | ||
} | ||
] | ||
}) | ||
template[1].submenu.push({ | ||
type: 'separator' | ||
}, { | ||
label: 'Speech', | ||
submenu: [ | ||
{ | ||
role: 'startspeaking' | ||
}, | ||
{ | ||
role: 'stopspeaking' | ||
}, | ||
{ | ||
label: 'Search Issues', | ||
click () { | ||
shell.openExternal('https://github.com/electron/electron/issues') | ||
} | ||
] | ||
}) | ||
} else { | ||
template.unshift({ | ||
label: 'File', | ||
submenu: [{ | ||
role: 'quit' | ||
}] | ||
}) | ||
} | ||
] | ||
} | ||
|
||
const menu = Menu.buildFromTemplate(template) | ||
Menu.setApplicationMenu(menu) | ||
} | ||
const template = [ | ||
isMac ? { role: 'appMenu' } : null, | ||
{ role: 'fileMenu' }, | ||
{ role: 'editMenu' }, | ||
{ role: 'viewMenu' }, | ||
{ role: 'windowMenu' }, | ||
helpMenu | ||
] | ||
|
||
module.exports = { | ||
setDefaultApplicationMenu | ||
return Menu.buildFromTemplate(template) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.