56b53e71aa
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.
20 lines
616 B
JavaScript
20 lines
616 B
JavaScript
const {EventEmitter} = require('events')
|
|
const {powerMonitor, PowerMonitor} = process.atomBinding('power_monitor')
|
|
|
|
// PowerMonitor is an EventEmitter.
|
|
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
|