Skip to content

Commit 57e490a

Browse files
committed
Fix Bug: Cannot quit by the tray button
1 parent c418683 commit 57e490a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

app/main.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ let tray: Tray | null = null;
1313

1414
// Settings
1515
let closeToTray = true;
16+
let forceQuit = false; // Flag to indicate we're trying to actually quit
1617

1718
// Check if app is running in development mode
1819
const args = process.argv.slice(1);
@@ -39,7 +40,10 @@ function createTray() {
3940
win?.setSkipTaskbar(false); // Show in taskbar
4041
}},
4142
{ type: 'separator' },
42-
{ label: 'Quit', click: () => { app.quit(); } }
43+
{ label: 'Quit', click: () => {
44+
forceQuit = true; // Set flag to bypass close-to-tray
45+
app.quit();
46+
}}
4347
]);
4448

4549
tray.setContextMenu(contextMenu);
@@ -316,10 +320,11 @@ function createWindow(): BrowserWindow {
316320

317321
// Close application
318322
ipcMain.on('close-app', () => {
319-
if (closeToTray) {
323+
if (closeToTray && !forceQuit) {
320324
win?.hide();
321-
win?.setSkipTaskbar(true);
325+
win?.setSkipTaskbar(true); // Hide from taskbar
322326
} else {
327+
forceQuit = true; // Ensure we're really quitting
323328
app.quit();
324329
}
325330
});
@@ -369,10 +374,10 @@ function createWindow(): BrowserWindow {
369374

370375
// Listen for window close event
371376
win.on('close', (e) => {
372-
if (closeToTray) {
377+
if (closeToTray && !forceQuit) {
373378
e.preventDefault();
374379
win?.hide();
375-
win?.setSkipTaskbar(true);
380+
win?.setSkipTaskbar(true); // Hide from taskbar
376381
}
377382
});
378383

@@ -478,6 +483,11 @@ function getCPUName() {
478483
try {
479484
app.commandLine.appendSwitch('class', 'tensorblock-desktop');
480485

486+
// Set force quit flag when app is about to quit
487+
app.on('before-quit', () => {
488+
forceQuit = true;
489+
});
490+
481491
// Initialize app when Electron is ready
482492
// Added delay to fix black background issue with transparent windows
483493
// See: https://github.com/electron/electron/issues/15947

0 commit comments

Comments
 (0)