Reputation: 13128
I have an Electron based app that runs in the macOS menu bar/the Windows tray area.
On Windows a system shutdown exits the app, but on macOS a system shutdown is interrupted due to the app not closing. How can I detect a shutdown event and close the app when the user has not explicitly requested the app to close?
Upvotes: 0
Views: 1487
Reputation: 13128
Simple solution:
import { app, powerMonitor } from 'electron';
powerMonitor.on('shutdown', () => {
app.quit();
});
Upvotes: 2
Reputation: 231
Check the electron 'app' module documentation here.
You can listen to the following events like 'before-quit' and 'will-quit' in order to handle the state of your application. Mind the note that this events won't fire in a Windows environment.
And always be sure that your application handles the 'quit' event in your main process like this
app.on('quit', () => {
app.quit();
});
Upvotes: 0