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 |
(...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; |
37 | 38 |
38 /** | 39 /** |
39 * If there aren't any filters, the default subscriptions are added. | 40 * If there aren't any filters, the default subscriptions are added. |
40 * However, if patterns.ini already did exist and/or any preference | 41 * 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 | 42 * is set to a non-default value, this indicates that this isn't the |
42 * first run, but something went wrong. | 43 * first run, but something went wrong. |
43 * | 44 * |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 } | 219 } |
219 } | 220 } |
220 | 221 |
221 return subscriptions; | 222 return subscriptions; |
222 }); | 223 }); |
223 } | 224 } |
224 | 225 |
225 return subscriptions; | 226 return subscriptions; |
226 } | 227 } |
227 | 228 |
228 function finishInitialization(subscriptions) | 229 function addSubscriptionsAndNotifyUser(subscriptions) |
229 { | 230 { |
230 if (subscriptionsCallback) | 231 if (subscriptionsCallback) |
231 subscriptions = subscriptionsCallback(subscriptions); | 232 subscriptions = subscriptionsCallback(subscriptions); |
232 | 233 |
233 for (let subscription of subscriptions) | 234 for (let subscription of subscriptions) |
234 { | 235 { |
235 FilterStorage.addSubscription(subscription); | 236 FilterStorage.addSubscription(subscription); |
236 if (subscription instanceof DownloadableSubscription && | 237 if (subscription instanceof DownloadableSubscription && |
237 !subscription.lastDownload) | 238 !subscription.lastDownload) |
238 Synchronizer.execute(subscription); | 239 Synchronizer.execute(subscription); |
239 } | 240 } |
240 | 241 |
241 if (!Prefs.suppress_first_run_page) | 242 // 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 // aren't new to Firefox users), and only if this version of the | |
245 // updates page hasn't been shown yet. | |
246 if (firstRun || info.platform == "chromium" && | |
247 updatesVersion > Prefs.last_updates_page_displayed) | |
242 { | 248 { |
243 let page = null; | 249 return Prefs.set("last_updates_page_displayed", updatesVersion).catch(() => |
244 if (firstRun) | |
245 { | 250 { |
246 page = "firstRun.html"; | 251 exports.dataCorrupted = true; |
247 } | 252 }).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 { | 253 { |
253 page = "updates.html"; | 254 if (!Prefs.suppress_first_run_page) |
254 } | 255 { |
255 | 256 // Always show the first run page if a data corruption was detected |
256 if (page) | 257 // (either though failure of reading from or writing to storage.local). |
257 { | 258 // The first run page notifies the user about the data corruption. |
258 browser.tabs.create({url: browser.extension.getURL(page)}); | 259 let url; |
259 | 260 if (firstRun || exports.dataCorrupted) |
260 // For new users and users that have already seen this updates page we | 261 url = "firstRun.html"; |
261 // want to avoid showing it again for subsequent updates. | 262 else |
262 Prefs.last_updates_page_displayed = updatesVersion; | 263 url = "updates.html"; |
263 } | 264 browser.tabs.create({url}); |
265 } | |
266 }); | |
264 } | 267 } |
265 | |
266 initNotifications(); | |
267 } | 268 } |
268 | 269 |
269 Promise.all([FilterNotifier.once("load"), | 270 Promise.all([ |
270 Prefs.untilLoaded]).then(detectFirstRun) | 271 FilterNotifier.once("load"), |
271 .then(getSubscriptions) | 272 Prefs.untilLoaded.catch(() => { exports.dataCorrupted = true; }) |
272 .then(finishInitialization); | 273 ]).then(detectFirstRun) |
274 .then(getSubscriptions) | |
275 .then(addSubscriptionsAndNotifyUser) | |
276 .then(setUninstallURL) | |
277 .then(initNotifications); | |
273 | 278 |
274 /** | 279 /** |
275 * Indicates whether the default filter subscriptions have been added | 280 * Indicates whether the default filter subscriptions have been added |
276 * again because there weren't any subscriptions even though this wasn't | 281 * again because there weren't any subscriptions even though this wasn't |
277 * the first run. | 282 * the first run. |
278 * | 283 * |
279 * @type {boolean} | 284 * @type {boolean} |
280 */ | 285 */ |
281 exports.reinitialized = false; | 286 exports.reinitialized = false; |
282 | 287 |
283 /** | 288 /** |
289 * Indicates whether a data corruption was detected. | |
290 * | |
291 * @type {boolean} | |
292 */ | |
293 exports.dataCorrupted = false; | |
kzar
2018/04/25 14:38:12
I just realised that this should probably be a get
Sebastian Noack
2018/04/25 14:46:23
Doesn't strike me as a huge issue. But more import
kzar
2018/04/25 14:57:04
Well I agree about not randomly changing "reinitia
Sebastian Noack
2018/04/25 17:08:56
I disagree about only changing either of them. So
| |
294 | |
295 /** | |
284 * Sets a callback that is called with an array of subscriptions to be added | 296 * 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 | 297 * during initialization. The callback must return an array of subscriptions |
286 * that will effectively be added. | 298 * that will effectively be added. |
287 * | 299 * |
288 * @param {function} callback | 300 * @param {function} callback |
289 */ | 301 */ |
290 exports.setSubscriptionsCallback = callback => | 302 exports.setSubscriptionsCallback = callback => |
291 { | 303 { |
292 subscriptionsCallback = callback; | 304 subscriptionsCallback = callback; |
293 }; | 305 }; |
OLD | NEW |