fix tray
This commit is contained in:
@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user