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

Commit

Permalink
Merge pull request #5382 from mozilla-services/suppress-library
Browse files Browse the repository at this point in the history
Fix #5381, remove Library and My Shots links
  • Loading branch information
ianb authored May 7, 2019
2 parents 9b2b685 + a5c2208 commit a430091
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 97 deletions.
9 changes: 1 addition & 8 deletions webextension/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,9 @@ this.main = (function() {

const manifest = browser.runtime.getManifest();
let backend;
let _hasAnyShots = false;

startBackground.serverStatus.then((status) => {
_hasAnyShots = status.hasAny;
}).catch((e) => {
log.warn("Cannot see server status", e);
});

exports.hasAnyShots = function() {
return _hasAnyShots;
return false;
};

let hasSeenOnboarding = browser.storage.local.get(["hasSeenOnboarding"]).then((result) => {
Expand Down
89 changes: 0 additions & 89 deletions webextension/background/startBackground.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ const startTime = Date.now();

this.startBackground = (function() {
const exports = {startTime};
// Wait until this many milliseconds to check the server for shots (for the purpose of migration warning):
const CHECK_SERVER_TIME = 5000; // 5 seconds
// If we want to pop open the tab showing the server status, wait this many milliseconds to open it:
const OPEN_SERVER_TAB_TIME = 5000; // 5 seconds
let hasSeenServerStatus = false;
let _resolveServerStatus;
exports.serverStatus = new Promise((resolve, reject) => {
_resolveServerStatus = {resolve, reject};
});
let backend;

const backgroundScripts = [
"log.js",
Expand Down Expand Up @@ -114,84 +104,5 @@ this.startBackground = (function() {
return loadedPromise;
}

async function checkExpiration() {
const manifest = await browser.runtime.getManifest();
for (const permission of manifest.permissions) {
if (/^https?:\/\//.test(permission)) {
backend = permission.replace(/\/*$/, "");
break;
}
}
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 {
let resp = await fetch(loginUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
deviceId: registrationInfo.deviceId,
secret: registrationInfo.secret,
}),
});
if (!resp.ok) {
throw new Error(`Bad login response: ${resp.status}`);
}
const { authHeader } = await resp.json();
resp = await fetch(hasShotsUrl, {
method: "GET",
credentials: "include",
headers: Object.assign({}, authHeader, {
"Content-Type": "application/json",
}),
});
if (!resp.ok) {
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);
}
}

exports.serverStatus.then((status) => {
if (status.hasAny) {
browser.experiments.screenshots.initLibraryButton();
}
if (status.hasIndefinite && !hasSeenServerStatus) {
setTimeout(async () => {
await browser.tabs.create({
url: `${backend}/hosting-shutdown`,
});
hasSeenServerStatus = true;
await browser.storage.local.set({hasSeenServerStatus});
}, OPEN_SERVER_TAB_TIME);
}
}).catch((e) => {
console.error("Error finding Screenshots server status:", String(e), e.stack);
});

setTimeout(() => {
window.requestIdleCallback(() => {
checkExpiration();
});
}, CHECK_SERVER_TIME);

return exports;
})();

0 comments on commit a430091

Please sign in to comment.