Hide the app window instead of closing it
Hey,
I have made a simple change to hide the application window instead of closing it. I believe it makes it more consistent with how other Mac apps work.
Regards, Marcin
Thanks! I agree this makes more sense. What about moving the whole fs.writeFileSync(...) part to the before-quit handler in order to get rid of the quit var?
Even if I move it there, don't we still need the variable?
I think you're right. I thought we could always prevent the default and hide the window but then the app will no longer exit.
Hm, what about multiple windows when using the app with multiple accounts?
How can I test that? I mean, is this in any way supported?
Ok, I will look into that and try to fix it. I didn't consider it when making the changes and it definitely breaks this functionality.
I have been using the application with my changes for 3 weeks already and it seems to work fine with one window. I am not really sure how it should behave with more than one window. After closing last window clicking on dock reopens the window. What should really be changed in case of any additional window?
The typically way to do this is below:
app.on('window-all-closed', () => {
// Don't quit on closing windows on MacOS
if (process.platform !== 'darwin') {
app.quit();
}
});
// Create window if it doesn't exist (such as closing on MacOS)
app.on('activate', () => {
if (!mainWindow) {
mainWindow = createMainWindow();
}
});