idle timer: don't check window.isFocused, force inactive on blur

This commit is contained in:
Scott Nonnenberg 2020-01-16 08:41:00 -08:00 committed by Ken Powers
parent 8dbbde6790
commit 7aaee0cb64

View file

@ -88,9 +88,15 @@
let activeHandlers = []; let activeHandlers = [];
let activeTimestamp = Date.now(); let activeTimestamp = Date.now();
window.addEventListener('blur', () => {
// Force inactivity
activeTimestamp = Date.now() - ACTIVE_TIMEOUT;
});
window.resetActiveTimer = _.throttle(() => { window.resetActiveTimer = _.throttle(() => {
const previouslyActive = window.isActive(); const previouslyActive = window.isActive();
activeTimestamp = Date.now(); activeTimestamp = Date.now();
if (!previouslyActive) { if (!previouslyActive) {
activeHandlers.forEach(handler => handler()); activeHandlers.forEach(handler => handler());
} }
@ -102,7 +108,7 @@
window.isActive = () => { window.isActive = () => {
const now = Date.now(); const now = Date.now();
return window.isFocused() && now <= activeTimestamp + ACTIVE_TIMEOUT; return now <= activeTimestamp + ACTIVE_TIMEOUT;
}; };
window.registerForActive = handler => activeHandlers.push(handler); window.registerForActive = handler => activeHandlers.push(handler);
window.unregisterForActive = handler => { window.unregisterForActive = handler => {