| Left: | ||
| Right: |
| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 /** @module subscriptionInit */ | 18 /** @module subscriptionInit */ |
| 19 | 19 |
| 20 "use strict"; | 20 "use strict"; |
| 21 | 21 |
| 22 const {Subscription, DownloadableSubscription, | 22 const {Subscription, DownloadableSubscription, |
| 23 SpecialSubscription} = require("subscriptionClasses"); | 23 SpecialSubscription} = require("subscriptionClasses"); |
| 24 const {FilterStorage} = require("filterStorage"); | 24 const {FilterStorage} = require("filterStorage"); |
| 25 const {FilterNotifier} = require("filterNotifier"); | 25 const {FilterNotifier} = require("filterNotifier"); |
| 26 const info = require("info"); | |
| 26 const {Prefs} = require("prefs"); | 27 const {Prefs} = require("prefs"); |
| 27 const {Synchronizer} = require("synchronizer"); | 28 const {Synchronizer} = require("synchronizer"); |
| 28 const {Utils} = require("utils"); | 29 const {Utils} = require("utils"); |
| 29 const {initNotifications} = require("notificationHelper"); | 30 const {initNotifications} = require("notificationHelper"); |
| 31 const {updatesVersion} = require("ui"); | |
| 30 | 32 |
| 31 let firstRun; | 33 let firstRun; |
| 32 let subscriptionsCallback = null; | 34 let subscriptionsCallback = null; |
| 33 | 35 |
| 34 /** | 36 /** |
| 35 * If there aren't any filters, the default subscriptions are added. | 37 * If there aren't any filters, the default subscriptions are added. |
| 36 * However, if patterns.ini already did exist and/or any preference | 38 * However, if patterns.ini already did exist and/or any preference |
| 37 * is set to a non-default value, this indicates that this isn't the | 39 * is set to a non-default value, this indicates that this isn't the |
| 38 * first run, but something went wrong. | 40 * first run, but something went wrong. |
| 39 * | 41 * |
| 40 * This function detects the first run, and makes sure that the user | 42 * This function detects the first run, and makes sure that the user |
| 41 * gets notified (on the first run page) if the data appears incomplete | 43 * gets notified (on the first run page) if the data appears incomplete |
| 42 * and therefore will be reinitialized. | 44 * and therefore will be reinitialized. |
| 43 */ | 45 */ |
| 44 function detectFirstRun() | 46 function detectFirstRun() |
| 45 { | 47 { |
| 46 firstRun = FilterStorage.subscriptions.length == 0; | 48 firstRun = FilterStorage.subscriptions.length == 0; |
| 47 | 49 |
| 48 if (firstRun && (!FilterStorage.firstRun || Prefs.currentVersion)) | 50 if (firstRun && (!FilterStorage.firstRun || Prefs.currentVersion)) |
| 49 exports.reinitialized = true; | 51 exports.reinitialized = true; |
| 50 | 52 |
| 51 Prefs.currentVersion = require("info").addonVersion; | 53 Prefs.currentVersion = info.addonVersion; |
| 52 } | 54 } |
| 53 | 55 |
| 54 /** | 56 /** |
| 55 * Determines whether to add the default ad blocking subscription. | 57 * Determines whether to add the default ad blocking subscription. |
| 56 * Returns true, if there are no filter subscriptions besides those | 58 * Returns true, if there are no filter subscriptions besides those |
| 57 * other subscriptions added automatically, and no custom filters. | 59 * other subscriptions added automatically, and no custom filters. |
| 58 * | 60 * |
| 59 * On first run, this logic should always result in true since there | 61 * On first run, this logic should always result in true since there |
| 60 * is no data and therefore no subscriptions. But it also causes the | 62 * is no data and therefore no subscriptions. But it also causes the |
| 61 * default ad blocking subscription to be added again after some | 63 * default ad blocking subscription to be added again after some |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 subscriptions = subscriptionsCallback(subscriptions); | 199 subscriptions = subscriptionsCallback(subscriptions); |
| 198 | 200 |
| 199 for (let subscription of subscriptions) | 201 for (let subscription of subscriptions) |
| 200 { | 202 { |
| 201 FilterStorage.addSubscription(subscription); | 203 FilterStorage.addSubscription(subscription); |
| 202 if (subscription instanceof DownloadableSubscription && | 204 if (subscription instanceof DownloadableSubscription && |
| 203 !subscription.lastDownload) | 205 !subscription.lastDownload) |
| 204 Synchronizer.execute(subscription); | 206 Synchronizer.execute(subscription); |
| 205 } | 207 } |
| 206 | 208 |
| 207 if (firstRun && !Prefs.suppress_first_run_page) | 209 if (!Prefs.suppress_first_run_page) |
| 208 browser.tabs.create({url: browser.extension.getURL("firstRun.html")}); | 210 { |
| 211 let page = null; | |
| 212 if (firstRun) | |
| 213 { | |
| 214 page = "firstRun.html"; | |
| 215 } | |
| 216 // For now we're limiting the updates page to users of | |
| 217 // Chromium-based browsers to gage its impact | |
| 218 else if (info.platform == "chromium" && | |
| 219 updatesVersion > Prefs.updates_version) | |
|
kzar
2018/01/23 10:07:13
Nit: This indentation is quite unusual, mind putti
Thomas Greiner
2018/01/25 11:09:45
Done.
I don't mind making such adjustments but it
kzar
2018/01/25 11:46:25
Yes, it would be great if ESLint could capture all
Thomas Greiner
2018/01/25 13:09:04
Just to clarify: I'm not talking about linting rul
| |
| 220 { | |
| 221 page = "updates.html"; | |
| 222 } | |
| 223 | |
| 224 if (page) | |
| 225 { | |
| 226 browser.tabs.create({url: browser.extension.getURL(page)}); | |
| 227 Prefs.updates_version = updatesVersion; | |
|
kzar
2018/01/23 10:07:13
Mind adding a short comment here explaining that w
Thomas Greiner
2018/01/25 11:09:45
Done.
kzar
2018/01/25 11:46:25
Thanks but the main thing I wanted to mention was
Thomas Greiner
2018/01/25 13:09:03
Done. My bad.
Note that I replaced "the next time
| |
| 228 } | |
| 229 } | |
| 209 | 230 |
| 210 initNotifications(); | 231 initNotifications(); |
| 211 } | 232 } |
| 212 | 233 |
| 213 Promise.all([FilterNotifier.once("load"), | 234 Promise.all([FilterNotifier.once("load"), |
| 214 Prefs.untilLoaded]).then(detectFirstRun) | 235 Prefs.untilLoaded]).then(detectFirstRun) |
| 215 .then(getSubscriptions) | 236 .then(getSubscriptions) |
| 216 .then(finishInitialization); | 237 .then(finishInitialization); |
| 217 | 238 |
| 218 /** | 239 /** |
| 219 * Indicates whether the default filter subscriptions have been added | 240 * Indicates whether the default filter subscriptions have been added |
| 220 * again because there weren't any subscriptions even though this wasn't | 241 * again because there weren't any subscriptions even though this wasn't |
| 221 * the first run. | 242 * the first run. |
| 222 * | 243 * |
| 223 * @type {boolean} | 244 * @type {boolean} |
| 224 */ | 245 */ |
| 225 exports.reinitialized = false; | 246 exports.reinitialized = false; |
| 226 | 247 |
| 227 /** | 248 /** |
| 228 * Sets a callback that is called with an array of subscriptions to be added | 249 * Sets a callback that is called with an array of subscriptions to be added |
| 229 * during initialization. The callback must return an array of subscriptions | 250 * during initialization. The callback must return an array of subscriptions |
| 230 * that will effectively be added. | 251 * that will effectively be added. |
| 231 * | 252 * |
| 232 * @param {function} callback | 253 * @param {function} callback |
| 233 */ | 254 */ |
| 234 exports.setSubscriptionsCallback = callback => | 255 exports.setSubscriptionsCallback = callback => |
| 235 { | 256 { |
| 236 subscriptionsCallback = callback; | 257 subscriptionsCallback = callback; |
| 237 }; | 258 }; |
| OLD | NEW |