From bb3ca31fd2985867327d5b30120202c01a40dece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20V=C3=A4nttinen?= Date: Fri, 11 Jan 2019 15:57:24 +0200 Subject: [PATCH] Disable browserAction update loop (#349) --- keepassxc-browser/background/browserAction.js | 20 +++++++++++++++++++ keepassxc-browser/background/init.js | 8 -------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/keepassxc-browser/background/browserAction.js b/keepassxc-browser/background/browserAction.js index 3f1ac52..dcfd8d5 100755 --- a/keepassxc-browser/background/browserAction.js +++ b/keepassxc-browser/background/browserAction.js @@ -6,6 +6,10 @@ const BLINK_TIMEOUT_DEFAULT = 7500; const BLINK_TIMEOUT_REDIRECT_THRESHOLD_TIME_DEFAULT = -1; const BLINK_TIMEOUT_REDIRECT_COUNT_DEFAULT = 1; +// Milliseconds for intervall (e.g. to update browserAction) +const _interval = 250; +let _loop = null; + browserAction.show = function(callback, tab) { let data = {}; if (!page.tabs[tab.id] || page.tabs[tab.id].stack.length === 0) { @@ -39,6 +43,7 @@ browserAction.update = function(interval) { if (data.visibleForMilliSeconds !== undefined && data.visibleForMilliSeconds !== -1) { if (data.visibleForMilliSeconds <= 0) { browserAction.stackPop(page.currentTabId); + browserAction.disableLoop(); browserAction.show(null, {'id': page.currentTabId}); page.clearCredentials(page.currentTabId); return; @@ -83,6 +88,7 @@ browserAction.showDefault = function(callback, tab) { } browserAction.stackUnshift(stackData, tab.id); + browserAction.disableLoop(); browserAction.show(null, tab); }); }; @@ -239,6 +245,7 @@ browserAction.setRememberPopup = function(tabId, username, password, url, userna popup: 'popup_remember.html' }; + browserAction.activateLoop(); browserAction.stackPush(stackData, id); page.tabs[id].credentials = { @@ -321,3 +328,16 @@ browserAction.ignoreSite = function(url) { }); }; +// Interval which updates the browserAction (e.g. blinking icon) +browserAction.activateLoop = function() { + if (_loop === null) { + _loop = setInterval(function() { + browserAction.update(_interval); + }, _interval); + } +}; + +browserAction.disableLoop = function() { + clearInterval(_loop); + _loop = null; +}; diff --git a/keepassxc-browser/background/init.js b/keepassxc-browser/background/init.js index 7f34359..842217f 100644 --- a/keepassxc-browser/background/init.js +++ b/keepassxc-browser/background/init.js @@ -13,9 +13,6 @@ keepass.migrateKeyRing().then(() => { }); }); -// Milliseconds for intervall (e.g. to update browserAction) -const _interval = 250; - /** * Generate information structure for created tab and invoke all needed * functions if tab is created in foreground @@ -136,8 +133,3 @@ browser.commands.onCommand.addListener((command) => { }); } }); - -// Interval which updates the browserAction (e.g. blinking icon) -window.setInterval(function() { - browserAction.update(_interval); -}, _interval);