jagadish
jagadish

Reputation: 21

handle operating system restart and shutdown in electron by an API call before restart and shutdown

How do I have an API call before the operating system restarts or shuts down in electron

Upvotes: 2

Views: 3255

Answers (2)

uTILLIty
uTILLIty

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

AlienHoboken
AlienHoboken

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

Related Questions