From 1bcd43088410a19ecc4ebed9cfcc6f6d16a8a916 Mon Sep 17 00:00:00 2001 From: Michael Honan Date: Thu, 16 May 2019 12:44:25 +1000 Subject: [PATCH] MacOS: Closing with red button won't open window again through tray icon (#40) * Fixed issue on MacOS where closing BW via the red button then reopening using tray icon wouldn't work * Added MacOS only condition to the window recreation of the toggleWindow method. Made createWindow public in WindowMain. --- src/electron/tray.main.ts | 19 ++++++++++++------- src/electron/window.main.ts | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/electron/tray.main.ts b/src/electron/tray.main.ts index 287d233303..7645cf6af7 100644 --- a/src/electron/tray.main.ts +++ b/src/electron/tray.main.ts @@ -121,14 +121,19 @@ export class TrayMain { } private toggleWindow() { - if (this.windowMain.win == null) { - return; - } - - if (this.windowMain.win.isVisible()) { - this.windowMain.win.hide(); + if (this.windowMain.win === null) { + if (process.platform === 'darwin') { + // On MacOS, closing the window via the red button destroys the BrowserWindow instance. + this.windowMain.createWindow().then(() => { + this.windowMain.win.show(); + }); + } } else { - this.windowMain.win.show(); + if (this.windowMain.win.isVisible()) { + this.windowMain.win.hide(); + } else { + this.windowMain.win.show(); + } } } diff --git a/src/electron/window.main.ts b/src/electron/window.main.ts index cb6d5d70df..865ea81368 100644 --- a/src/electron/window.main.ts +++ b/src/electron/window.main.ts @@ -81,7 +81,7 @@ export class WindowMain { }); } - private async createWindow() { + async createWindow(): Promise { this.windowStates[Keys.mainWindowSize] = await this.getWindowState(Keys.mainWindowSize, this.defaultWidth, this.defaultHeight);