OLD | NEW |
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 16 matching lines...) Expand all Loading... |
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 | 34 |
35 let firstRun; | 35 let firstRun; |
36 let subscriptionsCallback = null; | 36 let subscriptionsCallback = null; |
| 37 let reinitialized = false; |
| 38 let dataCorrupted = false; |
37 | 39 |
38 /** | 40 /** |
39 * If there aren't any filters, the default subscriptions are added. | 41 * If there aren't any filters, the default subscriptions are added. |
40 * However, if patterns.ini already did exist and/or any preference | 42 * However, if patterns.ini already did exist and/or any preference |
41 * 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 |
42 * first run, but something went wrong. | 44 * first run, but something went wrong. |
43 * | 45 * |
44 * 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 |
45 * 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 |
46 * and therefore will be reinitialized. | 48 * and therefore will be reinitialized. |
47 */ | 49 */ |
48 function detectFirstRun() | 50 function detectFirstRun() |
49 { | 51 { |
50 firstRun = FilterStorage.subscriptions.length == 0; | 52 firstRun = FilterStorage.subscriptions.length == 0; |
51 | 53 |
52 if (firstRun && (!FilterStorage.firstRun || Prefs.currentVersion)) | 54 if (firstRun && (!FilterStorage.firstRun || Prefs.currentVersion)) |
53 exports.reinitialized = true; | 55 reinitialized = true; |
54 | 56 |
55 Prefs.currentVersion = info.addonVersion; | 57 Prefs.currentVersion = info.addonVersion; |
56 } | 58 } |
57 | 59 |
58 /** | 60 /** |
59 * Determines whether to add the default ad blocking subscription. | 61 * Determines whether to add the default ad blocking subscription. |
60 * Returns true, if there are no filter subscriptions besides those | 62 * Returns true, if there are no filter subscriptions besides those |
61 * other subscriptions added automatically, and no custom filters. | 63 * other subscriptions added automatically, and no custom filters. |
62 * | 64 * |
63 * 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 } | 220 } |
219 } | 221 } |
220 | 222 |
221 return subscriptions; | 223 return subscriptions; |
222 }); | 224 }); |
223 } | 225 } |
224 | 226 |
225 return subscriptions; | 227 return subscriptions; |
226 } | 228 } |
227 | 229 |
228 function finishInitialization(subscriptions) | 230 function addSubscriptionsAndNotifyUser(subscriptions) |
229 { | 231 { |
230 if (subscriptionsCallback) | 232 if (subscriptionsCallback) |
231 subscriptions = subscriptionsCallback(subscriptions); | 233 subscriptions = subscriptionsCallback(subscriptions); |
232 | 234 |
233 for (let subscription of subscriptions) | 235 for (let subscription of subscriptions) |
234 { | 236 { |
235 FilterStorage.addSubscription(subscription); | 237 FilterStorage.addSubscription(subscription); |
236 if (subscription instanceof DownloadableSubscription && | 238 if (subscription instanceof DownloadableSubscription && |
237 !subscription.lastDownload) | 239 !subscription.lastDownload) |
238 Synchronizer.execute(subscription); | 240 Synchronizer.execute(subscription); |
239 } | 241 } |
240 | 242 |
241 if (!Prefs.suppress_first_run_page) | 243 // Show first run page or the updates page. The latter is only shown |
| 244 // on Chromium (since the current updates page announces features that |
| 245 // aren't new to Firefox users), and only if this version of the |
| 246 // updates page hasn't been shown yet. |
| 247 if (firstRun || info.platform == "chromium" && |
| 248 updatesVersion > Prefs.last_updates_page_displayed) |
242 { | 249 { |
243 let page = null; | 250 return Prefs.set("last_updates_page_displayed", updatesVersion).catch(() => |
244 if (firstRun) | |
245 { | 251 { |
246 page = "firstRun.html"; | 252 dataCorrupted = true; |
247 } | 253 }).then(() => |
248 // For now we're limiting the updates page to users of | |
249 // Chromium-based browsers to gage its impact | |
250 else if (info.platform == "chromium" && | |
251 updatesVersion > Prefs.last_updates_page_displayed) | |
252 { | 254 { |
253 page = "updates.html"; | 255 if (!Prefs.suppress_first_run_page) |
254 } | 256 { |
255 | 257 // Always show the first run page if a data corruption was detected |
256 if (page) | 258 // (either through failure of reading from or writing to storage.local). |
257 { | 259 // The first run page notifies the user about the data corruption. |
258 browser.tabs.create({url: browser.extension.getURL(page)}); | 260 let url; |
259 | 261 if (firstRun || dataCorrupted) |
260 // For new users and users that have already seen this updates page we | 262 url = "firstRun.html"; |
261 // want to avoid showing it again for subsequent updates. | 263 else |
262 Prefs.last_updates_page_displayed = updatesVersion; | 264 url = "updates.html"; |
263 } | 265 browser.tabs.create({url}); |
| 266 } |
| 267 }); |
264 } | 268 } |
265 | |
266 initNotifications(); | |
267 } | 269 } |
268 | 270 |
269 Promise.all([FilterNotifier.once("load"), | 271 Promise.all([ |
270 Prefs.untilLoaded]).then(detectFirstRun) | 272 FilterNotifier.once("load"), |
271 .then(getSubscriptions) | 273 Prefs.untilLoaded.catch(() => { dataCorrupted = true; }) |
272 .then(finishInitialization); | 274 ]).then(detectFirstRun) |
| 275 .then(getSubscriptions) |
| 276 .then(addSubscriptionsAndNotifyUser) |
| 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() }) |
| 280 .then(initNotifications); |
273 | 281 |
274 /** | 282 /** |
275 * Indicates whether the default filter subscriptions have been added | 283 * Gets a value indicating whether the default filter subscriptions have been |
276 * 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 |
277 * the first run. | 285 * the first run. |
278 * | 286 * |
279 * @type {boolean} | 287 * @return {boolean} |
280 */ | 288 */ |
281 exports.reinitialized = false; | 289 exports.isReinitialized = () => reinitialized; |
| 290 |
| 291 /** |
| 292 * Gets a value indicating whether a data corruption was detected. |
| 293 * |
| 294 * @return {boolean} |
| 295 */ |
| 296 exports.isDataCorrupted = () => dataCorrupted; |
282 | 297 |
283 /** | 298 /** |
284 * 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 |
285 * during initialization. The callback must return an array of subscriptions | 300 * during initialization. The callback must return an array of subscriptions |
286 * that will effectively be added. | 301 * that will effectively be added. |
287 * | 302 * |
288 * @param {function} callback | 303 * @param {function} callback |
289 */ | 304 */ |
290 exports.setSubscriptionsCallback = callback => | 305 exports.setSubscriptionsCallback = callback => |
291 { | 306 { |
292 subscriptionsCallback = callback; | 307 subscriptionsCallback = callback; |
293 }; | 308 }; |
OLD | NEW |