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
|
@ -145,6 +145,8 @@ Menu.setApplicationMenu = function (menu) {
|
|||
}
|
||||
|
||||
applicationMenu = menu
|
||||
v8Util.setHiddenValue(global, 'applicationMenuSet', true)
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
if (!menu) return
|
||||
menu._callMenuWillShow()
|
||||
|
|
58
lib/browser/default-menu.js
Normal file
58
lib/browser/default-menu.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
'use strict'
|
||||
|
||||
const { shell, Menu } = require('electron')
|
||||
const v8Util = process.atomBinding('v8_util')
|
||||
|
||||
const isMac = process.platform === 'darwin'
|
||||
|
||||
const setDefaultApplicationMenu = () => {
|
||||
if (v8Util.getHiddenValue(global, 'applicationMenuSet')) 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
|
||||
}
|
|
@ -184,5 +184,17 @@ if (currentPlatformSupportsAppIndicator()) {
|
|||
process.env.XDG_CURRENT_DESKTOP = 'Unity'
|
||||
}
|
||||
|
||||
// Quit when all windows are closed and no other one is listening to this.
|
||||
app.on('window-all-closed', () => {
|
||||
if (app.listenerCount('window-all-closed') === 1) {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
const { setDefaultApplicationMenu } = require('@electron/internal/browser/default-menu')
|
||||
|
||||
// Create default menu.
|
||||
app.once('ready', setDefaultApplicationMenu)
|
||||
|
||||
// Finally load app's main.js and transfer control to C++.
|
||||
Module._load(path.join(packagePath, mainStartupScript), Module, true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue