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

Commit

Permalink
Fix #3007, start background page if migration is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ianb committed Jun 12, 2017
1 parent 4cbc17c commit 77bd749
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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"
];

// 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
setTimeout(() => {
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);
}
});
}, CHECK_MIGRATION_DELAY);

let loadedPromise;

function loadIfNecessary() {
Expand Down

0 comments on commit 77bd749

Please sign in to comment.