From d13668544d5625c0aec83567960887029e1e333b Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Wed, 21 Mar 2018 15:21:38 -0400 Subject: [PATCH] Rename `IdleListener` to `IdleDetector` --- js/background.js | 4 ++-- .../{idle_listener.js => idle_detector.js} | 16 ++++++++-------- preload.js | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) rename js/modules/{idle_listener.js => idle_detector.js} (54%) diff --git a/js/background.js b/js/background.js index a39bc59f2..c48c3bcc3 100644 --- a/js/background.js +++ b/js/background.js @@ -14,7 +14,7 @@ ;(function() { 'use strict'; - const { IdleListener } = Signal; + const { IdleDetector } = Signal; const { Errors, Message } = window.Signal.Types; const { upgradeMessageSchema } = window.Signal.Migrations; @@ -76,7 +76,7 @@ storage.fetch(); - const idleListener = new IdleListener(); + const idleListener = new IdleDetector(); idleListener.on('idle', (event) => { console.log('Detected user idle:', event); }); diff --git a/js/modules/idle_listener.js b/js/modules/idle_detector.js similarity index 54% rename from js/modules/idle_listener.js rename to js/modules/idle_detector.js index d7ce3ba37..0ac975b64 100644 --- a/js/modules/idle_listener.js +++ b/js/modules/idle_detector.js @@ -2,10 +2,10 @@ const desktopIdle = require('desktop-idle'); const EventEmitter = require('events'); -const POLL_INTERVAL_MS = 10 * 1000; -const IDLE_THRESHOLD_MS = POLL_INTERVAL_MS; +const POLL_INTERVAL = 10; // seconds +const IDLE_THRESHOLD = POLL_INTERVAL; -class IdleListener extends EventEmitter { +class IdleDetector extends EventEmitter { constructor() { super(); this.intervalId = null; @@ -14,15 +14,15 @@ class IdleListener extends EventEmitter { start() { this.stop(); this.intervalId = setInterval(() => { - const idleDuration = desktopIdle.getIdleTime(); - const isIdle = idleDuration >= (IDLE_THRESHOLD_MS / 1000); + const idleDurationInSeconds = desktopIdle.getIdleTime(); + const isIdle = idleDurationInSeconds >= IDLE_THRESHOLD; if (!isIdle) { return; } - this.emit('idle', { idleDuration }); + this.emit('idle', { idleDurationInSeconds }); - }, POLL_INTERVAL_MS); + }, POLL_INTERVAL * 1000); } stop() { @@ -35,5 +35,5 @@ class IdleListener extends EventEmitter { } module.exports = { - IdleListener, + IdleDetector, }; diff --git a/preload.js b/preload.js index cae0288e8..029df59a6 100644 --- a/preload.js +++ b/preload.js @@ -124,8 +124,8 @@ window.Signal = window.Signal || {}; - const { IdleListener} = require('./js/modules/idle_listener'); - window.Signal.IdleListener = IdleListener; + const { IdleDetector} = require('./js/modules/idle_detector'); + window.Signal.IdleDetector = IdleDetector; window.Signal.Logs = require('./js/modules/logs'); window.Signal.OS = require('./js/modules/os');