From 63fe38b3f4dddd701b1a8da8a89e70c9d7fbc706 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Fri, 11 Dec 2020 15:46:20 +0100 Subject: [PATCH] Fix dock icon not working when minimized to menu bar, fix window listeners not working after closing the main window (#223) --- src/electron/tray.main.ts | 9 ++++++--- src/electron/window.main.ts | 9 ++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/electron/tray.main.ts b/src/electron/tray.main.ts index a782d95e12..bed712f5aa 100644 --- a/src/electron/tray.main.ts +++ b/src/electron/tray.main.ts @@ -1,5 +1,6 @@ import { app, + BrowserWindow, Menu, MenuItem, MenuItemConstructorOptions, @@ -57,15 +58,17 @@ export class TrayMain { if (await this.storageService.get(ElectronConstants.enableTrayKey)) { this.showTray(); } + } - this.windowMain.win.on('minimize', async (e: Event) => { + setupWindowListeners(win: BrowserWindow) { + win.on('minimize', async (e: Event) => { if (await this.storageService.get(ElectronConstants.enableMinimizeToTrayKey)) { e.preventDefault(); this.hideToTray(); } }); - this.windowMain.win.on('close', async (e: Event) => { + win.on('close', async (e: Event) => { if (await this.storageService.get(ElectronConstants.enableCloseToTrayKey)) { if (!this.windowMain.isQuitting) { e.preventDefault(); @@ -74,7 +77,7 @@ export class TrayMain { } }); - this.windowMain.win.on('show', async (e: Event) => { + win.on('show', async (e: Event) => { const enableTray = await this.storageService.get(ElectronConstants.enableTrayKey); if (!enableTray) { setTimeout(() => this.removeTray(false), 100); diff --git a/src/electron/window.main.ts b/src/electron/window.main.ts index e1a1498da8..6d7381c4b9 100644 --- a/src/electron/window.main.ts +++ b/src/electron/window.main.ts @@ -23,7 +23,8 @@ export class WindowMain { constructor(private storageService: StorageService, private hideTitleBar = false, private defaultWidth = 950, private defaultHeight = 600, - private argvCallback: (argv: string[]) => void = null) { } + private argvCallback: (argv: string[]) => void = null, + private createWindowCallback: (win: BrowserWindow) => void) { } init(): Promise { return new Promise((resolve, reject) => { @@ -82,6 +83,9 @@ export class WindowMain { // dock icon is clicked and there are no other windows open. if (this.win === null) { await this.createWindow(); + } else { + // Show the window when clicking on Dock icon + this.win.show(); } }); @@ -169,6 +173,9 @@ export class WindowMain { this.windowStateChangeHandler(Keys.mainWindowSize, this.win); }); + if (this.createWindowCallback) { + this.createWindowCallback(this.win); + } } async toggleAlwaysOnTop() {