From f8431242274771441c9e01961a9a99c042e990d2 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Thu, 8 Apr 2021 00:19:22 -0500 Subject: [PATCH] =?UTF-8?q?On=20MacOS,=20allow=20main=20win=20to=20close?= =?UTF-8?q?=20without=20qutting=20ala=20Thunderbird,=20don=E2=80=99t=20qui?= =?UTF-8?q?t=20if=20a=20composer=20is=20open?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/browser/mailspring-window.ts | 47 ++++++++++++++++------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/app/src/browser/mailspring-window.ts b/app/src/browser/mailspring-window.ts index 79bbbf906..b6f352109 100644 --- a/app/src/browser/mailspring-window.ts +++ b/app/src/browser/mailspring-window.ts @@ -216,30 +216,37 @@ export default class MailspringWindow extends EventEmitter { // // This uses the DOM's `beforeunload` event. this.browserWindow.on('close', event => { - if (this.neverClose && !global.application.isQuitting()) { + if (global.application.isQuitting()) { + return; + } + + const isLastWindow = global.application.windowManager.getVisibleWindowCount() === 1; + const isTrayEnabled = global.application.config.get('core.workspace.systemTray'); + const runWithoutWindowsOpen = isTrayEnabled || process.platform === 'darwin'; + + if (isLastWindow && !runWithoutWindowsOpen) { + // Tray indicator is switched off, closing the last window should quit the application. + app.quit(); + return; + } + + if (this.neverClose) { // For neverClose windows (like the main window) simply hide and // take out of full screen as long as the tray indicator is switched on. - if (global.application.config.get('core.workspace.systemTray')) { - // Tray indicator is switched on therefore hiding the main window only. - event.preventDefault(); - if (this.browserWindow.isFullScreen()) { - this.browserWindow.once('leave-full-screen', () => { - this.browserWindow.hide(); - }); - this.browserWindow.setFullScreen(false); - } else { + // Tray indicator is switched on therefore hiding the main window only. + event.preventDefault(); + if (this.browserWindow.isFullScreen()) { + this.browserWindow.once('leave-full-screen', () => { this.browserWindow.hide(); - } - - // HOWEVER! If the neverClose window is the last window open, and - // it looks like there's no windows actually quit the application - // on Linux & Windows. - if (!this.isSpec) { - global.application.windowManager.quitWinLinuxIfNoWindows(); - } + }); + this.browserWindow.setFullScreen(false); } else { - // Tray indicator is switched off, therefore quitting the application. - app.quit(); + this.browserWindow.hide(); + } + // HOWEVER! If the neverClose window is broken and is not actually loaded and + // no other windows are visible, quit because the user may not be able to. + if (!this.isSpec) { + global.application.windowManager.quitWinLinuxIfNoWindows(); } } });