Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/subscriptionInit.js

Issue 29664623: Issue 6403 - Updated adblockplusui dependency (Closed)
Patch Set: Cleaned up preferences Created Jan. 17, 2018, 5:45 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/prefs.js ('k') | metadata.chrome » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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");
30 31
32 /**
33 * The version of major updates that the user should be aware of.
34 * See also Prefs.updates_version
35 *
36 * @type {number}
37 */
38 const updatesVersion = 1;
39
31 let firstRun; 40 let firstRun;
32 let subscriptionsCallback = null; 41 let subscriptionsCallback = null;
33 42
34 /** 43 /**
35 * If there aren't any filters, the default subscriptions are added. 44 * If there aren't any filters, the default subscriptions are added.
36 * However, if patterns.ini already did exist and/or any preference 45 * 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 46 * is set to a non-default value, this indicates that this isn't the
38 * first run, but something went wrong. 47 * first run, but something went wrong.
39 * 48 *
40 * This function detects the first run, and makes sure that the user 49 * 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 50 * gets notified (on the first run page) if the data appears incomplete
42 * and therefore will be reinitialized. 51 * and therefore will be reinitialized.
43 */ 52 */
44 function detectFirstRun() 53 function detectFirstRun()
45 { 54 {
46 firstRun = FilterStorage.subscriptions.length == 0; 55 firstRun = FilterStorage.subscriptions.length == 0;
47 56
48 if (firstRun && (!FilterStorage.firstRun || Prefs.currentVersion)) 57 if (firstRun && (!FilterStorage.firstRun || Prefs.currentVersion))
49 exports.reinitialized = true; 58 exports.reinitialized = true;
50 59
51 Prefs.currentVersion = require("info").addonVersion; 60 Prefs.currentVersion = info.addonVersion;
52 } 61 }
53 62
54 /** 63 /**
55 * Determines whether to add the default ad blocking subscription. 64 * Determines whether to add the default ad blocking subscription.
56 * Returns true, if there are no filter subscriptions besides those 65 * Returns true, if there are no filter subscriptions besides those
57 * other subscriptions added automatically, and no custom filters. 66 * other subscriptions added automatically, and no custom filters.
58 * 67 *
59 * On first run, this logic should always result in true since there 68 * 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 69 * is no data and therefore no subscriptions. But it also causes the
61 * default ad blocking subscription to be added again after some 70 * default ad blocking subscription to be added again after some
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 subscriptions = subscriptionsCallback(subscriptions); 206 subscriptions = subscriptionsCallback(subscriptions);
198 207
199 for (let subscription of subscriptions) 208 for (let subscription of subscriptions)
200 { 209 {
201 FilterStorage.addSubscription(subscription); 210 FilterStorage.addSubscription(subscription);
202 if (subscription instanceof DownloadableSubscription && 211 if (subscription instanceof DownloadableSubscription &&
203 !subscription.lastDownload) 212 !subscription.lastDownload)
204 Synchronizer.execute(subscription); 213 Synchronizer.execute(subscription);
205 } 214 }
206 215
207 if (firstRun && !Prefs.suppress_first_run_page) 216 if (!Prefs.suppress_first_run_page)
208 browser.tabs.create({url: browser.extension.getURL("firstRun.html")}); 217 {
218 let page = null;
219 if (firstRun)
220 {
221 page = "firstRun.html";
222 }
223 // For now we're limiting the updates page to users of
224 // Chromium-based browsers to gage its impact
225 else if (info.platform == "chromium" &&
226 updatesVersion > Prefs.updates_version)
227 {
228 page = "updates.html";
229 }
230
231 if (page)
232 {
233 browser.tabs.create({url: browser.extension.getURL(page)});
234 Prefs.updates_version = updatesVersion;
235 }
236 }
209 237
210 initNotifications(); 238 initNotifications();
211 } 239 }
212 240
213 Promise.all([FilterNotifier.once("load"), 241 Promise.all([FilterNotifier.once("load"),
214 Prefs.untilLoaded]).then(detectFirstRun) 242 Prefs.untilLoaded]).then(detectFirstRun)
215 .then(getSubscriptions) 243 .then(getSubscriptions)
216 .then(finishInitialization); 244 .then(finishInitialization);
217 245
218 /** 246 /**
219 * Indicates whether the default filter subscriptions have been added 247 * Indicates whether the default filter subscriptions have been added
220 * again because there weren't any subscriptions even though this wasn't 248 * again because there weren't any subscriptions even though this wasn't
221 * the first run. 249 * the first run.
222 * 250 *
223 * @type {boolean} 251 * @type {boolean}
224 */ 252 */
225 exports.reinitialized = false; 253 exports.reinitialized = false;
226 254
227 /** 255 /**
228 * Sets a callback that is called with an array of subscriptions to be added 256 * 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 257 * during initialization. The callback must return an array of subscriptions
230 * that will effectively be added. 258 * that will effectively be added.
231 * 259 *
232 * @param {function} callback 260 * @param {function} callback
233 */ 261 */
234 exports.setSubscriptionsCallback = callback => 262 exports.setSubscriptionsCallback = callback =>
235 { 263 {
236 subscriptionsCallback = callback; 264 subscriptionsCallback = callback;
237 }; 265 };
OLDNEW
« no previous file with comments | « lib/prefs.js ('k') | metadata.chrome » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld