Avoid live-updating badgeCache object (#174)

This commit is contained in:
Maxim Baz
2019-09-27 14:33:39 +02:00
committed by GitHub
parent 8b22fdbfe9
commit 1292554759

View File

@@ -31,7 +31,8 @@ var authListeners = {};
var badgeCache = { var badgeCache = {
files: null, files: null,
settings: null, settings: null,
expires: Date.now() expires: Date.now(),
isRefreshing: false
}; };
// the last text copied to the clipboard is stored here in order to be cleared after 60 seconds // the last text copied to the clipboard is stored here in order to be cleared after 60 seconds
@@ -113,24 +114,24 @@ chrome.runtime.onInstalled.addListener(onExtensionInstalled);
async function updateMatchingPasswordsCount(tabId, forceRefresh = false) { async function updateMatchingPasswordsCount(tabId, forceRefresh = false) {
try { try {
if (forceRefresh || Date.now() > badgeCache.expires) { if (forceRefresh || Date.now() > badgeCache.expires) {
badgeCache = { badgeCache.isRefreshing = true;
files: null,
settings: null,
expires: Date.now() + 60 * 1000
};
badgeCache.settings = await getFullSettings(); let settings = await getFullSettings();
let response = await hostAction(settings, "list");
var response = await hostAction(badgeCache.settings, "list");
if (response.status != "ok") { if (response.status != "ok") {
throw new Error(JSON.stringify(response)); throw new Error(JSON.stringify(response));
} }
badgeCache.files = response.data.files; badgeCache = {
files: response.data.files,
settings: settings,
expires: Date.now() + 60 * 1000,
isRefreshing: false
};
} }
if (badgeCache.files === null) { if (badgeCache.isRefreshing) {
return; // badge cache refresh in progress return;
} }
try { try {