Left: | ||
Right: |
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 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 function supportsNotificationsWithButtons() | 140 function supportsNotificationsWithButtons() |
139 { | 141 { |
140 // Microsoft Edge (as of EdgeHTML 16) doesn't have the notifications API. | 142 // Microsoft Edge (as of EdgeHTML 16) doesn't have the notifications API. |
141 // Opera gives an asynchronous error when buttons are provided (we cannot | 143 // Opera gives an asynchronous error when buttons are provided (we cannot |
142 // detect that behavior without attempting to show a notification). | 144 // detect that behavior without attempting to show a notification). |
143 if (!("notifications" in browser) || info.application == "opera") | 145 if (!("notifications" in browser) || info.application == "opera") |
144 return false; | 146 return false; |
145 | 147 |
146 // Firefox throws synchronously if the "buttons" option is provided. | 148 // Firefox throws synchronously if the "buttons" option is provided. |
147 // If buttons are supported (i.e. on Chrome), this fails with | 149 // If buttons are supported (i.e. on Chrome), this fails with |
148 // a different error message due to missing required options. | 150 // an asynchronous error due to missing required options. |
149 // https://bugzilla.mozilla.org/show_bug.cgi?id=1190681 | 151 // https://bugzilla.mozilla.org/show_bug.cgi?id=1190681 |
150 try | 152 try |
151 { | 153 { |
152 browser.notifications.create({buttons: []}); | 154 browser.notifications.create({buttons: []}).catch(() => {}); |
153 } | 155 } |
154 catch (e) | 156 catch (e) |
155 { | 157 { |
156 if (e.toString().includes('"buttons" is unsupported')) | 158 if (e.toString().includes('"buttons" is unsupported')) |
157 return false; | 159 return false; |
158 } | 160 } |
159 | 161 |
160 return true; | 162 return true; |
161 } | 163 } |
162 | 164 |
(...skipping 55 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 |
242 { | 244 // on Chromium (since the current updates page announces features that |
243 let page = null; | 245 // aren't new to Firefox users), and only if this version of the |
244 if (firstRun || exports.dataCorrupted) | 246 // updates page hasn't been shown yet. |
kzar
2018/04/24 11:18:01
Well surely this would mean that the first run pag
Sebastian Noack
2018/04/24 11:26:26
Yes, that is the idea, to add this message to the
kzar
2018/04/24 13:34:00
Fair enough, I guess we need to also update the ad
| |
247 if (firstRun || info.platform == "chromium" && | |
248 updatesVersion > Prefs.last_updates_page_displayed) | |
249 { | |
250 return Prefs.set("last_updates_page_displayed", updatesVersion).catch(() => | |
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}); |
264 } | 266 } |
265 | 267 }); |
266 initNotifications(); | 268 } |
267 } | 269 } |
268 | 270 |
269 Promise.all([ | 271 Promise.all([ |
270 FilterNotifier.once("load"), | 272 FilterNotifier.once("load"), |
271 Prefs.untilLoaded.catch(() => { exports.dataCorrupted = true; }) | 273 Prefs.untilLoaded.catch(() => { dataCorrupted = true; }) |
272 ]).then(detectFirstRun) | 274 ]).then(detectFirstRun) |
273 .then(getSubscriptions) | 275 .then(getSubscriptions) |
274 .then(finishInitialization); | 276 .then(addSubscriptionsAndNotifyUser) |
275 | 277 // We have to require the "uninstall" module on demand, |
276 /** | 278 // as the "uninstall" module in turn requires this module. |
277 * Indicates whether the default filter subscriptions have been added | 279 .then(() => { require("./uninstall").setUninstallURL(); }) |
278 * again because there weren't any subscriptions even though this wasn't | 280 .then(initNotifications); |
281 | |
282 /** | |
283 * Gets a value indicating whether the default filter subscriptions have been | |
284 * added again because there weren't any subscriptions even though this wasn't | |
279 * the first run. | 285 * the first run. |
280 * | 286 * |
281 * @type {boolean} | 287 * @return {boolean} |
282 */ | 288 */ |
283 exports.reinitialized = false; | 289 exports.isReinitialized = () => reinitialized; |
284 | 290 |
285 /** | 291 /** |
286 * Indicates whether a data corruption was detcted. | 292 * Gets a value indicating whether a data corruption was detected. |
287 * | 293 * |
288 * @type {boolean} | 294 * @return {boolean} |
289 */ | 295 */ |
290 exports.dataCorrupted = false; | 296 exports.isDataCorrupted = () => dataCorrupted; |
291 | 297 |
292 /** | 298 /** |
293 * 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 |
294 * during initialization. The callback must return an array of subscriptions | 300 * during initialization. The callback must return an array of subscriptions |
295 * that will effectively be added. | 301 * that will effectively be added. |
296 * | 302 * |
297 * @param {function} callback | 303 * @param {function} callback |
298 */ | 304 */ |
299 exports.setSubscriptionsCallback = callback => | 305 exports.setSubscriptionsCallback = callback => |
300 { | 306 { |
301 subscriptionsCallback = callback; | 307 subscriptionsCallback = callback; |
302 }; | 308 }; |
LEFT | RIGHT |