| Index: lib/subscriptionInit.js |
| =================================================================== |
| --- a/lib/subscriptionInit.js |
| +++ b/lib/subscriptionInit.js |
| @@ -34,6 +34,8 @@ |
| let firstRun; |
| let subscriptionsCallback = null; |
| +let reinitialized = false; |
| +let dataCorrupted = false; |
| /** |
| * If there aren't any filters, the default subscriptions are added. |
| @@ -50,7 +52,7 @@ |
| firstRun = FilterStorage.subscriptions.length == 0; |
| if (firstRun && (!FilterStorage.firstRun || Prefs.currentVersion)) |
| - exports.reinitialized = true; |
| + reinitialized = true; |
| Prefs.currentVersion = info.addonVersion; |
| } |
| @@ -225,7 +227,7 @@ |
| return subscriptions; |
| } |
| -function finishInitialization(subscriptions) |
| +function addSubscriptionsAndNotifyUser(subscriptions) |
| { |
| if (subscriptionsCallback) |
| subscriptions = subscriptionsCallback(subscriptions); |
| @@ -238,47 +240,60 @@ |
| Synchronizer.execute(subscription); |
| } |
| - if (!Prefs.suppress_first_run_page) |
| + // Show first run page or the updates page. The latter is only shown |
| + // on Chromium (since the current updates page announces features that |
| + // aren't new to Firefox users), and only if this version of the |
| + // updates page hasn't been shown yet. |
| + if (firstRun || info.platform == "chromium" && |
| + updatesVersion > Prefs.last_updates_page_displayed) |
| { |
| - let page = null; |
| - if (firstRun) |
| - { |
| - page = "firstRun.html"; |
| - } |
| - // For now we're limiting the updates page to users of |
| - // Chromium-based browsers to gage its impact |
| - else if (info.platform == "chromium" && |
| - updatesVersion > Prefs.last_updates_page_displayed) |
| + return Prefs.set("last_updates_page_displayed", updatesVersion).catch(() => |
| { |
| - page = "updates.html"; |
| - } |
| - |
| - if (page) |
| + dataCorrupted = true; |
| + }).then(() => |
| { |
| - browser.tabs.create({url: browser.extension.getURL(page)}); |
| - |
| - // For new users and users that have already seen this updates page we |
| - // want to avoid showing it again for subsequent updates. |
| - Prefs.last_updates_page_displayed = updatesVersion; |
| - } |
| + if (!Prefs.suppress_first_run_page) |
| + { |
| + // Always show the first run page if a data corruption was detected |
| + // (either through failure of reading from or writing to storage.local). |
| + // The first run page notifies the user about the data corruption. |
| + let url; |
| + if (firstRun || dataCorrupted) |
| + url = "firstRun.html"; |
| + else |
| + url = "updates.html"; |
| + browser.tabs.create({url}); |
| + } |
| + }); |
| } |
| - |
| - initNotifications(); |
| } |
| -Promise.all([FilterNotifier.once("load"), |
| - Prefs.untilLoaded]).then(detectFirstRun) |
| - .then(getSubscriptions) |
| - .then(finishInitialization); |
| +Promise.all([ |
| + FilterNotifier.once("load"), |
| + Prefs.untilLoaded.catch(() => { dataCorrupted = true; }) |
| +]).then(detectFirstRun) |
| + .then(getSubscriptions) |
| + .then(addSubscriptionsAndNotifyUser) |
| + // We have to require the "uninstall" module on demand, |
| + // as the "uninstall" module in turn requires this module. |
| + .then(() => { require("./uninstall").setUninstallURL(); }) |
| + .then(initNotifications); |
| /** |
| - * Indicates whether the default filter subscriptions have been added |
| - * again because there weren't any subscriptions even though this wasn't |
| + * Gets a value indicating whether the default filter subscriptions have been |
| + * added again because there weren't any subscriptions even though this wasn't |
| * the first run. |
| * |
| - * @type {boolean} |
| + * @return {boolean} |
| */ |
| -exports.reinitialized = false; |
| +exports.isReinitialized = () => reinitialized; |
| + |
| +/** |
| + * Gets a value indicating whether a data corruption was detected. |
| + * |
| + * @return {boolean} |
| + */ |
| +exports.isDataCorrupted = () => dataCorrupted; |
| /** |
| * Sets a callback that is called with an array of subscriptions to be added |