Reputation: 21
How do I have an API call before the operating system restarts or shuts down in electron
Upvotes: 2
Views: 3255
Reputation: 475
See the session-end
event on the BrowserWindow
:
The docs state:
Emitted when window session is going to end due to force shutdown or machine restart or session log off.
Upvotes: 1
Reputation: 2810
Use node's process exit event to run code when the process is exiting, which happens when a system shutdown or restart occurs.
process.on('exit', function() {
// Shutdown logic
});
Obviously this will not work in the even of a "hard restart" or power loss, as those immediately terminate all processes. It will only with a graceful shutdown / restart.
Upvotes: 2