Skip to content

Commit

Permalink
fix(Windows): Fix losing window when "Keep Franz in background" is en…
Browse files Browse the repository at this point in the history
…abled
  • Loading branch information
adlk committed Mar 5, 2019
1 parent 03430f9 commit 78a3722
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/index.js
Expand Up @@ -223,20 +223,24 @@ const createWindow = () => {

// Emitted when the window is closed.
mainWindow.on('close', (e) => {
debug('Window: close window');
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
if (!willQuitApp && (settings.get('runInBackground') === undefined || settings.get('runInBackground'))) {
e.preventDefault();
if (isWindows) {
debug('Window: minimize');
mainWindow.minimize();

if (settings.get('minimizeToSystemTray')) {
debug('Skip taskbar: true');
mainWindow.setSkipTaskbar(true);
}
} else {
debug('Window: hide');
mainWindow.hide();
}

if (isWindows) {
mainWindow.setSkipTaskbar(true);
}
} else {
app.quit();
}
Expand All @@ -248,39 +252,47 @@ const createWindow = () => {
app.wasMaximized = app.isMaximized;

if (settings.get('minimizeToSystemTray')) {
debug('Skip taskbar: true');
mainWindow.setSkipTaskbar(true);
trayIcon.show();
}
});

mainWindow.on('maximize', () => {
debug('Window: maximize');
app.isMaximized = true;
});

mainWindow.on('unmaximize', () => {
debug('Window: unmaximize');
app.isMaximized = false;
});

mainWindow.on('restore', () => {
debug('Window: restore');
mainWindow.setSkipTaskbar(false);

if (app.wasMaximized) {
debug('Window: was maximized before, maximize window');
mainWindow.maximize();
}

if (!settings.get('enableSystemTray')) {
debug('Tray: hiding tray icon');
trayIcon.hide();
}
});

mainWindow.on('show', () => {
debug('Skip taskbar: false');
mainWindow.setSkipTaskbar(false);
});

app.mainWindow = mainWindow;
app.isMaximized = mainWindow.isMaximized();

mainWindow.webContents.on('new-window', (e, url) => {
debug('Open url', url);
e.preventDefault();
shell.openExternal(url);
});
Expand Down Expand Up @@ -360,7 +372,10 @@ app.on('window-all-closed', () => {
// to stay active until the user quits explicitly with Cmd + Q
if (settings.get('runInBackground') === undefined
|| settings.get('runInBackground')) {
debug('Window: all windows closed, quit app');
app.quit();
} else {
debug('Window: don\'t quit app');
}
});

Expand Down

2 comments on commit 78a3722

@imaginarny
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit reintroduced issue (#763 #1006) on windows when you can't minimize to task bar or close window completely. Fix in my PR was removed. #1038

@imaginarny
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adlk bump? It got into stable anyway. I have no idea why is this condition on close action if (settings.get('minimizeToSystemTray')) back again so I won't post another issue nor pull request.

Please sign in to comment.