From b63c222162d21a938ce1e0bb16d99dc71ee0c4ed Mon Sep 17 00:00:00 2001 From: Haze <709547807@qq.com> Date: Wed, 11 Feb 2026 18:31:50 +0800 Subject: [PATCH] fix(electron): register activate handler after app is ready (#55) --- electron/main/index.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index d8556cfc9..5faa56f80 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -171,7 +171,17 @@ async function initialize(): Promise { } // Application lifecycle -app.whenReady().then(initialize); +app.whenReady().then(() => { + initialize(); + + // Register activate handler AFTER app is ready to prevent + // "Cannot create BrowserWindow before app is ready" on macOS. + app.on('activate', () => { + if (BrowserWindow.getAllWindows().length === 0) { + mainWindow = createWindow(); + } + }); +}); app.on('window-all-closed', () => { if (process.platform !== 'darwin') { @@ -179,12 +189,6 @@ app.on('window-all-closed', () => { } }); -app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) { - mainWindow = createWindow(); - } -}); - app.on('before-quit', async () => { await gatewayManager.stop(); });