2016-05-15 09:41:30 -04:00
|
|
|
const {EventEmitter} = require('events')
|
2016-08-02 20:38:35 +09:00
|
|
|
const {powerMonitor, PowerMonitor} = process.atomBinding('power_monitor')
|
2016-01-11 18:40:23 -08:00
|
|
|
|
2017-11-01 23:05:27 -05:00
|
|
|
// PowerMonitor is an EventEmitter.
|
2016-08-02 20:38:35 +09:00
|
|
|
Object.setPrototypeOf(PowerMonitor.prototype, EventEmitter.prototype)
|
2017-11-01 23:05:27 -05:00
|
|
|
EventEmitter.call(powerMonitor)
|
2016-01-11 18:40:23 -08:00
|
|
|
|
2018-02-05 15:28:58 +09:00
|
|
|
// On Linux we need to call blockShutdown() to subscribe to shutdown event.
|
|
|
|
if (process.platform === 'linux') {
|
|
|
|
powerMonitor.on('newListener', (event) => {
|
|
|
|
if (event === 'shutdown' && powerMonitor.listenerCount('shutdown') === 0) {
|
|
|
|
powerMonitor.blockShutdown()
|
|
|
|
}
|
|
|
|
})
|
2017-12-07 10:10:40 -03:00
|
|
|
|
2018-02-05 15:28:58 +09:00
|
|
|
powerMonitor.on('removeListener', (event) => {
|
|
|
|
if (event === 'shutdown' && powerMonitor.listenerCount('shutdown') === 0) {
|
|
|
|
powerMonitor.unblockShutdown()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2017-12-07 10:10:40 -03:00
|
|
|
|
2016-03-24 13:15:04 -07:00
|
|
|
module.exports = powerMonitor
|