Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

fix: Fixes #410. Prevent duplicate listeners #437

Merged
merged 1 commit into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ 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', () => {
pino.info('Finished hiding window');
});

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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ const pino = Pino();

function setupWinListeners (fetherApp) {
const {
hideWindow,
moveWindowUp,
onWindowClose,
options,
processSaveWinPosition,
win
} = fetherApp;
Expand Down Expand Up @@ -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', () => {
Expand All @@ -77,6 +75,10 @@ function setupWinListeners (fetherApp) {

fetherApp.emit('after-closed-window');
});

win.on('minimize', () => {
fetherApp.emit('minimize-window');
});
}

export default setupWinListeners;
10 changes: 8 additions & 2 deletions packages/fether-electron/src/main/app/methods/showWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function showWindow (fetherApp, trayPos) {
win
} = fetherApp;

pino.info('Showing window id: ', fetherApp.win && fetherApp.win.id);

if (!win) {
createWindow(fetherApp);
}
Expand Down Expand Up @@ -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');
}
Expand Down
10 changes: 9 additions & 1 deletion packages/fether-electron/src/main/app/methods/windowClear.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down