Attempt to minimise the window first rather than exiting

This commit is contained in:
Germain Souquet 2021-03-25 14:50:33 +00:00
parent 9cdea580d3
commit 3d18ff16d1

View file

@ -927,6 +927,16 @@ app.on('ready', async () => {
mainWindow = global.mainWindow = null;
});
mainWindow.on('close', async (e) => {
// If we are not quitting and have a tray icon then minimize to tray
if (!global.appQuitting && (tray.hasTray() || process.platform === 'darwin')) {
// On Mac, closing the window just hides it
// (this is generally how single-window Mac apps
// behave, eg. Mail.app)
e.preventDefault();
mainWindow.hide();
return false;
}
if (store.get('warnBeforeExit', true)) {
const shouldCancelCloseRequest = dialog.showMessageBoxSync(mainWindow, {
type: "question",
@ -941,16 +951,6 @@ app.on('ready', async () => {
return false;
}
}
// If we are not quitting and have a tray icon then minimize to tray
if (!global.appQuitting && (tray.hasTray() || process.platform === 'darwin')) {
// On Mac, closing the window just hides it
// (this is generally how single-window Mac apps
// behave, eg. Mail.app)
e.preventDefault();
mainWindow.hide();
return false;
}
});
if (process.platform === 'win32') {