fix: set default menu in will-finish-launching event (#23214)

This commit is contained in:
Cheng Zhao 2020-04-24 02:51:31 +09:00 committed by GitHub
parent 69ccf94d45
commit cb6a1e2c5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View file

@ -207,10 +207,9 @@ const { setDefaultApplicationMenu } = require('@electron/internal/browser/defaul
// Create default menu.
//
// Note that the task must be added before loading any app, so we can make sure
// the call is maded before any user window is created, otherwise the default
// menu may show even when user explicitly hides the menu.
app.whenReady().then(setDefaultApplicationMenu);
// The |will-finish-launching| event is emitted before |ready| event, so default
// menu is set before any user window is created.
app.once('will-finish-launching', setDefaultApplicationMenu);
if (packagePath) {
// Finally load app's main.js and transfer control to C++.

View file

@ -1,7 +1,10 @@
const { app, BrowserWindow } = require('electron');
let win;
app.whenReady().then(function () {
// This test uses "app.once('ready')" while the |test-menu-null| test uses
// "app.whenReady()", the 2 APIs have slight difference on timing to cover
// more cases.
app.once('ready', function () {
win = new BrowserWindow({});
win.setMenuBarVisibility(false);