Skip to content

Commit cb6a1e2

Browse files
authored
fix: set default menu in will-finish-launching event (electron#23214)
1 parent 69ccf94 commit cb6a1e2

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/browser/init.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,9 @@ const { setDefaultApplicationMenu } = require('@electron/internal/browser/defaul
207207

208208
// Create default menu.
209209
//
210-
// Note that the task must be added before loading any app, so we can make sure
211-
// the call is maded before any user window is created, otherwise the default
212-
// menu may show even when user explicitly hides the menu.
213-
app.whenReady().then(setDefaultApplicationMenu);
210+
// The |will-finish-launching| event is emitted before |ready| event, so default
211+
// menu is set before any user window is created.
212+
app.once('will-finish-launching', setDefaultApplicationMenu);
214213

215214
if (packagePath) {
216215
// Finally load app's main.js and transfer control to C++.

spec-main/fixtures/api/test-menu-visibility/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
const { app, BrowserWindow } = require('electron');
22

33
let win;
4-
app.whenReady().then(function () {
4+
// This test uses "app.once('ready')" while the |test-menu-null| test uses
5+
// "app.whenReady()", the 2 APIs have slight difference on timing to cover
6+
// more cases.
7+
app.once('ready', function () {
58
win = new BrowserWindow({});
69
win.setMenuBarVisibility(false);
710

0 commit comments

Comments
 (0)