app.quit()
is the correct function for doing this.
Quote from the documentation (https://github.com/electron/electron/blob/master/docs/api/app.md)
Try to close all windows. The before-quit
event will be emitted first. If all windows are successfully closed, the will-quit
event will be emitted and by default the application will terminate.
This method guarantees that all beforeunload
and unload event handlers
are correctly executed. It is possible that a window cancels the
quitting by returning false
in the beforeunload
event handler.
You could correct the behavior in Windows if you close the app directly on button click, instead of closing the window -> listening to the event -> and quitting the app
const app = require('electron').remote.app;
const close = document.getElementById('myCloseButton');
close.on('click',function(){
app.quit();
});
Note: app.exit()
also exists but it does not send the events mentioned above, so it should only be used if necessary.