diff --git a/src-electron/electron-main.ts b/src-electron/electron-main.ts index 515602ff14..16e7fa3c0f 100644 --- a/src-electron/electron-main.ts +++ b/src-electron/electron-main.ts @@ -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'; @@ -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'); + } } });