From 7aaee0cb64e9404565c168cf4ce7bf682d357be6 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 16 Jan 2020 08:41:00 -0800 Subject: [PATCH] idle timer: don't check window.isFocused, force inactive on blur --- js/background.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/background.js b/js/background.js index bc5630577..6c5a7dc8d 100644 --- a/js/background.js +++ b/js/background.js @@ -88,9 +88,15 @@ let activeHandlers = []; let activeTimestamp = Date.now(); + window.addEventListener('blur', () => { + // Force inactivity + activeTimestamp = Date.now() - ACTIVE_TIMEOUT; + }); + window.resetActiveTimer = _.throttle(() => { const previouslyActive = window.isActive(); activeTimestamp = Date.now(); + if (!previouslyActive) { activeHandlers.forEach(handler => handler()); } @@ -102,7 +108,7 @@ window.isActive = () => { const now = Date.now(); - return window.isFocused() && now <= activeTimestamp + ACTIVE_TIMEOUT; + return now <= activeTimestamp + ACTIVE_TIMEOUT; }; window.registerForActive = handler => activeHandlers.push(handler); window.unregisterForActive = handler => {