From 77bd749882225f6664cba1ffb69e6c10d240c7dd Mon Sep 17 00:00:00 2001 From: Ian Bicking Date: Mon, 12 Jun 2017 11:16:21 -0500 Subject: [PATCH] Fix #3007, start background page if migration is needed --- .../webextension/background/communication.js | 1 + .../background/startBackground.js | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/addon/webextension/background/communication.js b/addon/webextension/background/communication.js index f1184fb8f2..7f642ba653 100644 --- a/addon/webextension/background/communication.js +++ b/addon/webextension/background/communication.js @@ -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; } diff --git a/addon/webextension/background/startBackground.js b/addon/webextension/background/startBackground.js index 63f9159145..093f8f8097 100644 --- a/addon/webextension/background/startBackground.js +++ b/addon/webextension/background/startBackground.js @@ -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); @@ -32,7 +35,6 @@ this.startBackground = (function() { }); }); - browser.contextMenus.create({ id: "create-screenshot", title: browser.i18n.getMessage("contextMenuLabel"), @@ -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() {