Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ var authListeners = {};
var badgeCache = {
files: 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
Expand Down Expand Up @@ -113,24 +114,24 @@ chrome.runtime.onInstalled.addListener(onExtensionInstalled);
async function updateMatchingPasswordsCount(tabId, forceRefresh = false) {
try {
if (forceRefresh || Date.now() > badgeCache.expires) {
badgeCache = {
files: null,
settings: null,
expires: Date.now() + 60 * 1000
};

badgeCache.settings = await getFullSettings();
badgeCache.isRefreshing = true;

var response = await hostAction(badgeCache.settings, "list");
let settings = await getFullSettings();
let response = await hostAction(settings, "list");
if (response.status != "ok") {
throw new Error(JSON.stringify(response));
}

badgeCache.files = response.data.files;
badgeCache = {
files: response.data.files,
settings: settings,
expires: Date.now() + 60 * 1000,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use magic numbers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 will extract

isRefreshing: false
};
}

if (badgeCache.files === null) {
return; // badge cache refresh in progress
if (badgeCache.isRefreshing) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this condition belong at the very beginning of the function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it does, remnants of the previous logic 👍

return;
}

try {
Expand Down