Small refactoring
This commit is contained in:
@@ -112,6 +112,10 @@ chrome.runtime.onInstalled.addListener(onExtensionInstalled);
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
async function updateMatchingPasswordsCount(tabId, forceRefresh = false) {
|
async function updateMatchingPasswordsCount(tabId, forceRefresh = false) {
|
||||||
|
if (badgeCache.isRefreshing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (forceRefresh || Date.now() > badgeCache.expires) {
|
if (forceRefresh || Date.now() > badgeCache.expires) {
|
||||||
badgeCache.isRefreshing = true;
|
badgeCache.isRefreshing = true;
|
||||||
@@ -122,18 +126,15 @@ async function updateMatchingPasswordsCount(tabId, forceRefresh = false) {
|
|||||||
throw new Error(JSON.stringify(response));
|
throw new Error(JSON.stringify(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CACHE_TTL_MS = 60 * 1000;
|
||||||
badgeCache = {
|
badgeCache = {
|
||||||
files: response.data.files,
|
files: response.data.files,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
expires: Date.now() + 60 * 1000,
|
expires: Date.now() + CACHE_TTL_MS,
|
||||||
isRefreshing: false
|
isRefreshing: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (badgeCache.isRefreshing) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const tab = await chrome.tabs.get(tabId);
|
const tab = await chrome.tabs.get(tabId);
|
||||||
badgeCache.settings.host = new URL(tab.url).hostname;
|
badgeCache.settings.host = new URL(tab.url).hostname;
|
||||||
|
Reference in New Issue
Block a user