From c9c824a57a69a7747dfb44d4daff47bc9520a9e9 Mon Sep 17 00:00:00 2001 From: Luke Schoen Date: Thu, 21 Feb 2019 14:14:14 +0100 Subject: [PATCH] fix: Fixes #410. Prevent duplicate listeners --- .../src/main/app/methods/setupAppListeners.js | 8 ++++++-- .../src/main/app/methods/setupWinListeners.js | 8 +++++--- .../fether-electron/src/main/app/methods/showWindow.js | 10 ++++++++-- .../src/main/app/methods/windowClear.js | 10 +++++++++- .../src/main/app/options/config/index.js | 2 +- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/packages/fether-electron/src/main/app/methods/setupAppListeners.js b/packages/fether-electron/src/main/app/methods/setupAppListeners.js index cc67bfed7..1e70cb467 100644 --- a/packages/fether-electron/src/main/app/methods/setupAppListeners.js +++ b/packages/fether-electron/src/main/app/methods/setupAppListeners.js @@ -42,8 +42,12 @@ function setupAppListeners (fetherApp) { pino.info(`Ready to use ${productName}`); }); + fetherApp.on('minimize-window', () => { + pino.info('Minimized window'); + }); + fetherApp.on('hide-window', () => { - pino.info('Hiding window on blur since not on top'); + pino.info('Hiding window'); }); fetherApp.on('after-hide-window', () => { @@ -51,7 +55,7 @@ function setupAppListeners (fetherApp) { }); fetherApp.on('blur-window', () => { - pino.info('Blur window since lost focus when on top'); + pino.info('Blur window'); }); fetherApp.on('after-moved-window-position-saved', () => { diff --git a/packages/fether-electron/src/main/app/methods/setupWinListeners.js b/packages/fether-electron/src/main/app/methods/setupWinListeners.js index 0560bfa07..aef96d890 100644 --- a/packages/fether-electron/src/main/app/methods/setupWinListeners.js +++ b/packages/fether-electron/src/main/app/methods/setupWinListeners.js @@ -12,10 +12,8 @@ const pino = Pino(); function setupWinListeners (fetherApp) { const { - hideWindow, moveWindowUp, onWindowClose, - options, processSaveWinPosition, win } = fetherApp; @@ -65,7 +63,7 @@ function setupWinListeners (fetherApp) { }); win.on('blur', () => { - options.alwaysOnTop ? fetherApp.emit('blur-window') : hideWindow(fetherApp); + fetherApp.emit('blur-window'); }); win.on('close', () => { @@ -77,6 +75,10 @@ function setupWinListeners (fetherApp) { fetherApp.emit('after-closed-window'); }); + + win.on('minimize', () => { + fetherApp.emit('minimize-window'); + }); } export default setupWinListeners; diff --git a/packages/fether-electron/src/main/app/methods/showWindow.js b/packages/fether-electron/src/main/app/methods/showWindow.js index 6849b1e25..189439686 100644 --- a/packages/fether-electron/src/main/app/methods/showWindow.js +++ b/packages/fether-electron/src/main/app/methods/showWindow.js @@ -21,6 +21,8 @@ function showWindow (fetherApp, trayPos) { win } = fetherApp; + pino.info('Showing window id: ', fetherApp.win && fetherApp.win.id); + if (!win) { createWindow(fetherApp); } @@ -75,8 +77,12 @@ function showWindow (fetherApp, trayPos) { fetherApp.win.setPosition(x, y); fetherApp.win.show(); - setupWinListeners(fetherApp); - setupWin32Listeners(fetherApp); + if (!fetherApp.hasSetupWinListeners) { + setupWinListeners(fetherApp); + setupWin32Listeners(fetherApp); + + fetherApp.hasSetupWinListeners = true; + } fetherApp.emit('after-show-window'); } diff --git a/packages/fether-electron/src/main/app/methods/windowClear.js b/packages/fether-electron/src/main/app/methods/windowClear.js index 9d65ed25c..277d36455 100644 --- a/packages/fether-electron/src/main/app/methods/windowClear.js +++ b/packages/fether-electron/src/main/app/methods/windowClear.js @@ -8,7 +8,15 @@ function windowClear (fetherApp) { if (win) { // Remove relevant events when window object deleted - const events = ['close', 'move', 'moved', 'resize']; + const events = [ + 'blur', + 'close', + 'closed', + 'minimize', + 'move', + 'moved', + 'resize' + ]; for (let event in events) { win.removeAllListeners(event); } diff --git a/packages/fether-electron/src/main/app/options/config/index.js b/packages/fether-electron/src/main/app/options/config/index.js index b4313bc20..cf4b57030 100644 --- a/packages/fether-electron/src/main/app/options/config/index.js +++ b/packages/fether-electron/src/main/app/options/config/index.js @@ -47,7 +47,7 @@ const windowPosition = // API docs: https://electronjs.org/docs/api/browser-window const DEFAULT_OPTIONS = { - alwaysOnTop: true, + alwaysOnTop: false, dir: staticPath, frame: true, height: 640,