LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 13 matching lines...) Expand all Loading... |
24 SpecialSubscription} = | 24 SpecialSubscription} = |
25 require("../adblockpluscore/lib/subscriptionClasses"); | 25 require("../adblockpluscore/lib/subscriptionClasses"); |
26 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage"); | 26 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage"); |
27 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); | 27 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); |
28 const info = require("../buildtools/info"); | 28 const info = require("../buildtools/info"); |
29 const {Prefs} = require("./prefs"); | 29 const {Prefs} = require("./prefs"); |
30 const {Synchronizer} = require("../adblockpluscore/lib/synchronizer"); | 30 const {Synchronizer} = require("../adblockpluscore/lib/synchronizer"); |
31 const {Utils} = require("./utils"); | 31 const {Utils} = require("./utils"); |
32 const {initNotifications} = require("./notificationHelper"); | 32 const {initNotifications} = require("./notificationHelper"); |
33 const {updatesVersion} = require("../adblockplusui/lib/prefs"); | 33 const {updatesVersion} = require("../adblockplusui/lib/prefs"); |
34 const {setUninstallURL} = require("./uninstall"); | |
35 | 34 |
36 let firstRun; | 35 let firstRun; |
37 let subscriptionsCallback = null; | 36 let subscriptionsCallback = null; |
| 37 let reinitialized = false; |
| 38 let dataCorrupted = false; |
38 | 39 |
39 /** | 40 /** |
40 * If there aren't any filters, the default subscriptions are added. | 41 * If there aren't any filters, the default subscriptions are added. |
41 * However, if patterns.ini already did exist and/or any preference | 42 * However, if patterns.ini already did exist and/or any preference |
42 * is set to a non-default value, this indicates that this isn't the | 43 * is set to a non-default value, this indicates that this isn't the |
43 * first run, but something went wrong. | 44 * first run, but something went wrong. |
44 * | 45 * |
45 * This function detects the first run, and makes sure that the user | 46 * This function detects the first run, and makes sure that the user |
46 * gets notified (on the first run page) if the data appears incomplete | 47 * gets notified (on the first run page) if the data appears incomplete |
47 * and therefore will be reinitialized. | 48 * and therefore will be reinitialized. |
48 */ | 49 */ |
49 function detectFirstRun() | 50 function detectFirstRun() |
50 { | 51 { |
51 firstRun = FilterStorage.subscriptions.length == 0; | 52 firstRun = FilterStorage.subscriptions.length == 0; |
52 | 53 |
53 if (firstRun && (!FilterStorage.firstRun || Prefs.currentVersion)) | 54 if (firstRun && (!FilterStorage.firstRun || Prefs.currentVersion)) |
54 exports.reinitialized = true; | 55 reinitialized = true; |
55 | 56 |
56 Prefs.currentVersion = info.addonVersion; | 57 Prefs.currentVersion = info.addonVersion; |
57 } | 58 } |
58 | 59 |
59 /** | 60 /** |
60 * Determines whether to add the default ad blocking subscription. | 61 * Determines whether to add the default ad blocking subscription. |
61 * Returns true, if there are no filter subscriptions besides those | 62 * Returns true, if there are no filter subscriptions besides those |
62 * other subscriptions added automatically, and no custom filters. | 63 * other subscriptions added automatically, and no custom filters. |
63 * | 64 * |
64 * On first run, this logic should always result in true since there | 65 * On first run, this logic should always result in true since there |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 242 |
242 // Show first run page or the updates page. The latter is only shown | 243 // Show first run page or the updates page. The latter is only shown |
243 // on Chromium (since the current updates page announces features that | 244 // on Chromium (since the current updates page announces features that |
244 // aren't new to Firefox users), and only if this version of the | 245 // aren't new to Firefox users), and only if this version of the |
245 // updates page hasn't been shown yet. | 246 // updates page hasn't been shown yet. |
246 if (firstRun || info.platform == "chromium" && | 247 if (firstRun || info.platform == "chromium" && |
247 updatesVersion > Prefs.last_updates_page_displayed) | 248 updatesVersion > Prefs.last_updates_page_displayed) |
248 { | 249 { |
249 return Prefs.set("last_updates_page_displayed", updatesVersion).catch(() => | 250 return Prefs.set("last_updates_page_displayed", updatesVersion).catch(() => |
250 { | 251 { |
251 exports.dataCorrupted = true; | 252 dataCorrupted = true; |
252 }).then(() => | 253 }).then(() => |
253 { | 254 { |
254 if (!Prefs.suppress_first_run_page) | 255 if (!Prefs.suppress_first_run_page) |
255 { | 256 { |
256 // Always show the first run page if a data corruption was detected | 257 // Always show the first run page if a data corruption was detected |
257 // (either though failure of reading from or writing to storage.local). | 258 // (either through failure of reading from or writing to storage.local). |
258 // The first run page notifies the user about the data corruption. | 259 // The first run page notifies the user about the data corruption. |
259 let url; | 260 let url; |
260 if (firstRun || exports.dataCorrupted) | 261 if (firstRun || dataCorrupted) |
261 url = "firstRun.html"; | 262 url = "firstRun.html"; |
262 else | 263 else |
263 url = "updates.html"; | 264 url = "updates.html"; |
264 browser.tabs.create({url}); | 265 browser.tabs.create({url}); |
265 } | 266 } |
266 }); | 267 }); |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
270 Promise.all([ | 271 Promise.all([ |
271 FilterNotifier.once("load"), | 272 FilterNotifier.once("load"), |
272 Prefs.untilLoaded.catch(() => { exports.dataCorrupted = true; }) | 273 Prefs.untilLoaded.catch(() => { dataCorrupted = true; }) |
273 ]).then(detectFirstRun) | 274 ]).then(detectFirstRun) |
274 .then(getSubscriptions) | 275 .then(getSubscriptions) |
275 .then(addSubscriptionsAndNotifyUser) | 276 .then(addSubscriptionsAndNotifyUser) |
276 .then(setUninstallURL) | 277 // We have to require the "uninstall" module on demand, |
| 278 // as the "uninstall" module in turn requires this module. |
| 279 .then(() => { require("./uninstall").setUninstallURL(); }) |
277 .then(initNotifications); | 280 .then(initNotifications); |
278 | 281 |
279 /** | 282 /** |
280 * Indicates whether the default filter subscriptions have been added | 283 * Gets a value indicating whether the default filter subscriptions have been |
281 * again because there weren't any subscriptions even though this wasn't | 284 * added again because there weren't any subscriptions even though this wasn't |
282 * the first run. | 285 * the first run. |
283 * | 286 * |
284 * @type {boolean} | 287 * @return {boolean} |
285 */ | 288 */ |
286 exports.reinitialized = false; | 289 exports.isReinitialized = () => reinitialized; |
287 | 290 |
288 /** | 291 /** |
289 * Indicates whether a data corruption was detected. | 292 * Gets a value indicating whether a data corruption was detected. |
290 * | 293 * |
291 * @type {boolean} | 294 * @return {boolean} |
292 */ | 295 */ |
293 exports.dataCorrupted = false; | 296 exports.isDataCorrupted = () => dataCorrupted; |
294 | 297 |
295 /** | 298 /** |
296 * Sets a callback that is called with an array of subscriptions to be added | 299 * Sets a callback that is called with an array of subscriptions to be added |
297 * during initialization. The callback must return an array of subscriptions | 300 * during initialization. The callback must return an array of subscriptions |
298 * that will effectively be added. | 301 * that will effectively be added. |
299 * | 302 * |
300 * @param {function} callback | 303 * @param {function} callback |
301 */ | 304 */ |
302 exports.setSubscriptionsCallback = callback => | 305 exports.setSubscriptionsCallback = callback => |
303 { | 306 { |
304 subscriptionsCallback = callback; | 307 subscriptionsCallback = callback; |
305 }; | 308 }; |
LEFT | RIGHT |