Skip to content

Commit

Permalink
fix: implement quit verification logic for macOS Cmd-Q
Browse files Browse the repository at this point in the history
  • Loading branch information
sircharlo committed Nov 15, 2024
1 parent 2d3f063 commit 12297e0
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src-electron/electron-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import {
} from 'electron';

import { PLATFORM } from './constants';
import { cancelAllDownloads } from './main/downloads';
import { initScreenListeners } from './main/screen';
import { initSessionListeners } from './main/session';
import { initUpdater } from './main/updater';
import { closeOtherWindows, sendToWindow } from './main/window/window-base';
import {
authorizedClose,
createMainWindow,
mainWindow,
toggleAuthorizedClose,
} from './main/window/window-main';
import { errorCatcher } from './utils';

Expand All @@ -41,10 +43,16 @@ app.on('window-all-closed', () => {
if (PLATFORM !== 'darwin') app.quit();
});

app.on('before-quit', () => {
if (PLATFORM === 'darwin') {
toggleAuthorizedClose(true);
mainWindow?.close();
app.on('before-quit', (e) => {
if (PLATFORM === 'darwin' && mainWindow) {
if (authorizedClose) {
cancelAllDownloads();
closeOtherWindows(mainWindow);
mainWindow?.close();
} else {
e.preventDefault();
sendToWindow(mainWindow, 'attemptedClose');
}
}
});

Expand Down

0 comments on commit 12297e0

Please sign in to comment.