Implement powerMonitor 'shutdown' event for Linux.
The event is emitted when the OS is rebooting/shutting down, and allows an electron app to call `e.preventDefault()` in order to delay shutdown and exit cleanly.
This commit is contained in:
parent
28d96e2d29
commit
56b53e71aa
6 changed files with 104 additions and 2 deletions
|
@ -5,4 +5,16 @@ const {powerMonitor, PowerMonitor} = process.atomBinding('power_monitor')
|
|||
Object.setPrototypeOf(PowerMonitor.prototype, EventEmitter.prototype)
|
||||
EventEmitter.call(powerMonitor)
|
||||
|
||||
powerMonitor.on('newListener', (event) => {
|
||||
if (event === 'shutdown' && powerMonitor.listenerCount('shutdown') === 0) {
|
||||
powerMonitor.blockShutdown()
|
||||
}
|
||||
})
|
||||
|
||||
powerMonitor.on('removeListener', (event) => {
|
||||
if (event === 'shutdown' && powerMonitor.listenerCount('shutdown') === 0) {
|
||||
powerMonitor.unblockShutdown()
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = powerMonitor
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue