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