feat: use default-app behavior in packaged apps (#16310)
Unify the behavior between default app and packaged apps: - create default application menu unless the app has one - default window-all-closed handling unless the app handles the event
This commit is contained in:
parent
8e2ab8b20b
commit
23d44e322d
11 changed files with 133 additions and 37 deletions
|
@ -7,8 +7,6 @@ const Module = require('module')
|
|||
const path = require('path')
|
||||
const url = require('url')
|
||||
|
||||
const { setDefaultApplicationMenu } = require('./menu')
|
||||
|
||||
// Parse command line options.
|
||||
const argv = process.argv.slice(1)
|
||||
|
||||
|
@ -59,18 +57,6 @@ if (nextArgIsRequire) {
|
|||
process.exit(1)
|
||||
}
|
||||
|
||||
// Quit when all windows are closed and no other one is listening to this.
|
||||
app.on('window-all-closed', () => {
|
||||
if (app.listeners('window-all-closed').length === 1 && !option.interactive) {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
// Create default menu.
|
||||
app.once('ready', () => {
|
||||
setDefaultApplicationMenu()
|
||||
})
|
||||
|
||||
// Set up preload modules
|
||||
if (option.modules.length > 0) {
|
||||
Module._preloadModules(option.modules)
|
||||
|
@ -142,6 +128,9 @@ function startRepl () {
|
|||
process.exit(1)
|
||||
}
|
||||
|
||||
// prevent quitting
|
||||
app.on('window-all-closed', () => {})
|
||||
|
||||
const repl = require('repl')
|
||||
repl.start('> ').on('exit', () => {
|
||||
process.exit(0)
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
'use strict'
|
||||
|
||||
const { shell, Menu } = require('electron')
|
||||
|
||||
const isMac = process.platform === 'darwin'
|
||||
|
||||
const setDefaultApplicationMenu = () => {
|
||||
if (Menu.getApplicationMenu()) return
|
||||
|
||||
const helpMenu = {
|
||||
role: 'help',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Learn More',
|
||||
click () {
|
||||
shell.openExternalSync('https://electronjs.org')
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Documentation',
|
||||
click () {
|
||||
shell.openExternalSync(
|
||||
`https://github.com/electron/electron/tree/v${process.versions.electron}/docs#readme`
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Community Discussions',
|
||||
click () {
|
||||
shell.openExternalSync('https://discuss.atom.io/c/electron')
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Search Issues',
|
||||
click () {
|
||||
shell.openExternalSync('https://github.com/electron/electron/issues')
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const template = [
|
||||
...(isMac ? [{ role: 'appMenu' }] : []),
|
||||
{ role: 'fileMenu' },
|
||||
{ role: 'editMenu' },
|
||||
{ role: 'viewMenu' },
|
||||
{ role: 'windowMenu' },
|
||||
helpMenu
|
||||
]
|
||||
|
||||
const menu = Menu.buildFromTemplate(template)
|
||||
Menu.setApplicationMenu(menu)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setDefaultApplicationMenu
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue