From e3421436baa6060e51c48d3bfa73b392884f8afa Mon Sep 17 00:00:00 2001 From: mayneyao Date: Thu, 24 Oct 2024 00:18:06 +0800 Subject: [PATCH] fix(desktop): ensure app fully exits on window close --- electron/main.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/electron/main.ts b/electron/main.ts index 9ed11707..c6938058 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -152,17 +152,26 @@ function createTray() { } } +function destroyTray() { + if (tray) { + tray.destroy(); + tray = null; + } +} + app.whenReady().then(() => { win = createWindow() createTray(); win.on('close', (event) => { if (!forceQuit) { - event.preventDefault(); if (process.platform === 'darwin') { + event.preventDefault(); win?.hide(); } else { - win?.minimize(); + forceQuit = true; + destroyTray(); + app.quit(); } } }); @@ -178,5 +187,6 @@ app.on('activate', () => { ipcMain.handle('quit-app', () => { forceQuit = true; + destroyTray(); app.quit(); });