Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #5332, cache startup server check
Browse files Browse the repository at this point in the history
This applies to the migration code that runs on startup
  • Loading branch information
ianb committed Jan 29, 2019
1 parent 803d3b3 commit 9f9b04a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion webextension/background/startBackground.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,19 @@ this.startBackground = (function() {
break;
}
}
const result = await browser.storage.local.get(["registrationInfo", "hasSeenServerStatus"]);
const result = await browser.storage.local.get(["registrationInfo", "hasSeenServerStatus", "hasShotsResponse"]);
hasSeenServerStatus = result.hasSeenServerStatus;
const { registrationInfo } = result;
if (!backend || !registrationInfo || !registrationInfo.registered) {
// The add-on hasn't been used, or at least no upload has occurred
_resolveServerStatus.resolve({hasIndefinite: false, hasAny: false});
return;
}
if (result.hasShotsResponse) {
// We've already retrieved information from the server
_resolveServerStatus.resolve(result.hasShotsResponse);
return;
}
const loginUrl = `${backend}/api/login`;
const hasShotsUrl = `${backend}/api/has-shots`;
try {
Expand Down Expand Up @@ -158,6 +163,7 @@ this.startBackground = (function() {
throw new Error(`Bad response from server: ${resp.status}`);
}
const body = await resp.json();
browser.storage.local.set({hasShotsResponse: body});
_resolveServerStatus.resolve(body);
} catch (e) {
_resolveServerStatus.reject(e);
Expand Down

0 comments on commit 9f9b04a

Please sign in to comment.