fix: harden application lifecycle and termination logic to prevent defunct processes and orphaned tray icons

This commit is contained in:
2026-02-21 14:51:46 +01:00
parent c1fd7cee49
commit 28a053a42c

View File

@@ -164,7 +164,12 @@ const updateTrayMenu = () => {
{ label: 'Sync Now', enabled: !!config?.enabled, click: () => syncAccounts(true) }, { label: 'Sync Now', enabled: !!config?.enabled, click: () => syncAccounts(true) },
{ type: 'separator' }, { type: 'separator' },
{ label: 'Show Dashboard', click: () => { if (mainWindow) { mainWindow.show(); mainWindow.focus(); } } }, { label: 'Show Dashboard', click: () => { if (mainWindow) { mainWindow.show(); mainWindow.focus(); } } },
{ label: 'Quit', click: () => { (app as any).isQuitting = true; app.quit(); } } { label: 'Quit', click: () => {
console.log('[Tray] Quit requested');
(app as any).isQuitting = true;
if (tray) tray.destroy();
app.quit();
} }
]); ]);
tray.setContextMenu(contextMenu); tray.setContextMenu(contextMenu);
}; };
@@ -466,9 +471,32 @@ app.whenReady().then(() => {
steamClient.startWatching(handleLocalAccountsFound); steamClient.startWatching(handleLocalAccountsFound);
}); });
app.on('window-all-closed', () => { if (process.platform !== 'darwin' && (app as any).isQuitting) app.quit(); }); // Support for background running
(app as any).isQuitting = false;
app.on('before-quit', () => {
console.log('[App] Preparing to quit...');
(app as any).isQuitting = true;
if (tray) {
tray.destroy();
tray = null;
}
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin' && (app as any).isQuitting) {
app.quit();
}
});
app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) createWindow(); else mainWindow?.show(); }); app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) createWindow(); else mainWindow?.show(); });
// Handle terminal termination (Ctrl+C)
process.on('SIGINT', () => {
(app as any).isQuitting = true;
app.quit();
});
// --- IPC Handlers --- // --- IPC Handlers ---
ipcMain.handle('get-accounts', () => store.get('accounts')); ipcMain.handle('get-accounts', () => store.get('accounts'));
ipcMain.handle('get-server-config', () => store.get('serverConfig')); ipcMain.handle('get-server-config', () => store.get('serverConfig'));