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 #3017 from mozilla-services/notice-page-shot
Browse files Browse the repository at this point in the history
Fix #3007, start background page if migration is needed
  • Loading branch information
ianb authored Jun 12, 2017
2 parents e0d9782 + 87a28fd commit 20be05d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions addon/webextension/background/communication.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ this.communication = (function() {
};

function isBootstrapMissingError(error) {
// Note: some of this logic is copied into startBackground.js's getOldDeviceInfo call
if (!error) {
return false;
}
Expand Down
28 changes: 27 additions & 1 deletion addon/webextension/background/startBackground.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ this.startBackground = (function() {
"background/main.js"
];

// Maximum milliseconds to wait before checking for migration possibility
const CHECK_MIGRATION_DELAY = 2000;

browser.browserAction.onClicked.addListener((tab) => {
loadIfNecessary().then(() => {
main.onClicked(tab);
Expand All @@ -32,7 +35,6 @@ this.startBackground = (function() {
});
});


browser.contextMenus.create({
id: "create-screenshot",
title: browser.i18n.getMessage("contextMenuLabel"),
Expand Down Expand Up @@ -69,6 +71,30 @@ this.startBackground = (function() {
return true;
});

// We delay this check (by CHECK_MIGRATION_DELAY) just to avoid piling too
// many things onto browser/add-on startup
requestIdleCallback(() => {
browser.runtime.sendMessage({funcName: "getOldDeviceInfo"}).then((result) => {
if (result && result.type == "success" && result.value) {
// There is a possible migration to run, so we'll load the entire background
// page and continue the process
return loadIfNecessary();
}
if (!result) {
throw new Error("Got no result from getOldDeviceInfo");
}
if (result.type == "error") {
throw new Error(`Error from getOldDeviceInfo: ${result.name}`);
}
}).catch((error) => {
if (error && error.message == "Could not establish connection. Receiving end does not exist") {
// Just a missing bootstrap.js, ignore
} else {
console.error("Screenshots error checking for Page Shot migration:", error);
}
});
}, {timeout: CHECK_MIGRATION_DELAY});

let loadedPromise;

function loadIfNecessary() {
Expand Down
4 changes: 3 additions & 1 deletion bin/build-scripts/update_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
if last_version:
last_parts = last_version.split(".")
version_parts = version.split(".")
if last_parts[0] == version_parts[0] and last_parts[1] == version_parts[1] and int(last_parts[2]) >= int(version_parts[2]):
if (last_parts[0] == version_parts[0] and
last_parts[1] == version_parts[1] and
int(last_parts[2]) >= int(version_parts[2])):
now_timestamp += 1
continue
break
Expand Down

0 comments on commit 20be05d

Please # to comment.