Rename IdleListener to IdleDetector

This commit is contained in:
Daniel Gasienica 2018-03-21 15:21:38 -04:00
parent 92ace67846
commit d13668544d
3 changed files with 12 additions and 12 deletions

View file

@ -0,0 +1,39 @@
const desktopIdle = require('desktop-idle');
const EventEmitter = require('events');
const POLL_INTERVAL = 10; // seconds
const IDLE_THRESHOLD = POLL_INTERVAL;
class IdleDetector extends EventEmitter {
constructor() {
super();
this.intervalId = null;
}
start() {
this.stop();
this.intervalId = setInterval(() => {
const idleDurationInSeconds = desktopIdle.getIdleTime();
const isIdle = idleDurationInSeconds >= IDLE_THRESHOLD;
if (!isIdle) {
return;
}
this.emit('idle', { idleDurationInSeconds });
}, POLL_INTERVAL * 1000);
}
stop() {
if (!this.intervalId) {
return;
}
clearInterval(this.intervalId);
}
}
module.exports = {
IdleDetector,
};