From 7fbb9fa78a13fcf0bd62702ede00d36849a4d088 Mon Sep 17 00:00:00 2001 From: aurinex Date: Mon, 22 Dec 2025 18:29:47 +0500 Subject: [PATCH] fix tray --- src/main/main.ts | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index f9be41d..9d8e6fd 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -96,7 +96,16 @@ const ensureTray = () => { { type: 'separator' }, { label: 'Выход', - click: () => app.quit(), + click: () => { + isQuitting = true; + + if (mainWindow) { + mainWindow.removeAllListeners('close'); + mainWindow.destroy(); // ⬅ КЛЮЧЕВО + } + + app.quit(); + }, }, ]); @@ -119,6 +128,7 @@ const applyLoginItemSettings = () => { let tray: Tray | null = null; let isAuthed = false; +let isQuitting = false; let mainWindow: BrowserWindow | null = null; @@ -152,7 +162,19 @@ function buildTrayMenu() { { type: 'separator' }, { label: 'Показать', click: () => { mainWindow?.show(); mainWindow?.focus(); } }, - { label: 'Выход', click: () => app.quit() }, + { + label: 'Выход', + click: () => { + isQuitting = true; + + if (mainWindow) { + mainWindow.removeAllListeners('close'); + mainWindow.destroy(); // ⬅ КЛЮЧЕВО + } + + app.quit(); + }, + }, ]; tray?.setContextMenu(Menu.buildFromTemplate(template)); @@ -259,9 +281,8 @@ const createWindow = async () => { }); mainWindow.on('close', (e) => { - if (launcherSettings.closeToTray) { + if (!isQuitting && launcherSettings.closeToTray) { e.preventDefault(); - ensureTray(); mainWindow?.hide(); } }); @@ -317,6 +338,10 @@ app.on('window-all-closed', () => { } }); +app.on('before-quit', () => { + isQuitting = true; +}); + app .whenReady() .then(() => {