idle timer: don't check window.isFocused, force inactive on blur
This commit is contained in:
parent
8dbbde6790
commit
7aaee0cb64
1 changed files with 7 additions and 1 deletions
|
@ -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 => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue