Disable browserAction update loop (#349)

This commit is contained in:
Sami Vänttinen 2019-01-11 15:57:24 +02:00 committed by Janek Bevendorff
parent e8e731ea75
commit bb3ca31fd2
2 changed files with 20 additions and 8 deletions

View file

@ -6,6 +6,10 @@ const BLINK_TIMEOUT_DEFAULT = 7500;
const BLINK_TIMEOUT_REDIRECT_THRESHOLD_TIME_DEFAULT = -1; const BLINK_TIMEOUT_REDIRECT_THRESHOLD_TIME_DEFAULT = -1;
const BLINK_TIMEOUT_REDIRECT_COUNT_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) { browserAction.show = function(callback, tab) {
let data = {}; let data = {};
if (!page.tabs[tab.id] || page.tabs[tab.id].stack.length === 0) { 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 !== undefined && data.visibleForMilliSeconds !== -1) {
if (data.visibleForMilliSeconds <= 0) { if (data.visibleForMilliSeconds <= 0) {
browserAction.stackPop(page.currentTabId); browserAction.stackPop(page.currentTabId);
browserAction.disableLoop();
browserAction.show(null, {'id': page.currentTabId}); browserAction.show(null, {'id': page.currentTabId});
page.clearCredentials(page.currentTabId); page.clearCredentials(page.currentTabId);
return; return;
@ -83,6 +88,7 @@ browserAction.showDefault = function(callback, tab) {
} }
browserAction.stackUnshift(stackData, tab.id); browserAction.stackUnshift(stackData, tab.id);
browserAction.disableLoop();
browserAction.show(null, tab); browserAction.show(null, tab);
}); });
}; };
@ -239,6 +245,7 @@ browserAction.setRememberPopup = function(tabId, username, password, url, userna
popup: 'popup_remember.html' popup: 'popup_remember.html'
}; };
browserAction.activateLoop();
browserAction.stackPush(stackData, id); browserAction.stackPush(stackData, id);
page.tabs[id].credentials = { 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;
};

View file

@ -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 * Generate information structure for created tab and invoke all needed
* functions if tab is created in foreground * 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);