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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 // No matching necessary if there's nothing to match | 131 // No matching necessary if there's nothing to match |
132 if (typeof url !== "string" && !(MATCHER in notification)) | 132 if (typeof url !== "string" && !(MATCHER in notification)) |
133 return true; | 133 return true; |
134 | 134 |
135 // Notification shouldn't match if extension is disabled | 135 // Notification shouldn't match if extension is disabled |
136 if (!Prefs.enabled) | 136 if (!Prefs.enabled) |
137 return false; | 137 return false; |
138 | 138 |
139 // Notification shouldn't match if matching cannot be done | 139 // Notification shouldn't match if matching cannot be done |
140 if (typeof url !== "string" || !(MATCHER in notification)) | 140 if (typeof url !== "string" || !(MATCHER in notification)) |
141 return false; | 141 return false; |
sergei
2018/01/30 17:25:05
It somehow conflicts with above
if (typeof url !==
Thomas Greiner
2018/01/30 19:17:53
The logic behind it is that if the notification do
sergei
2018/01/30 21:06:48
Acknowledged.
| |
142 | 142 |
143 let host; | 143 let host; |
144 try | 144 try |
145 { | 145 { |
146 host = new URL(url).hostname; | 146 host = new URL(url).hostname; |
147 } | 147 } |
148 catch (e) | 148 catch (e) |
149 { | 149 { |
150 host = ""; | 150 host = ""; |
151 } | 151 } |
(...skipping 28 matching lines...) Expand all Loading... | |
180 * Regularly fetches notifications and decides which to show. | 180 * Regularly fetches notifications and decides which to show. |
181 * @class | 181 * @class |
182 */ | 182 */ |
183 let Notification = exports.Notification = | 183 let Notification = exports.Notification = |
184 { | 184 { |
185 /** | 185 /** |
186 * Called on module startup. | 186 * Called on module startup. |
187 */ | 187 */ |
188 init() | 188 init() |
189 { | 189 { |
190 let {data} = Prefs.notificationdata; | 190 let {data} = Prefs.notificationdata; |
sergei
2018/01/30 17:25:05
Prefs' properties can be not ready yet, I would re
sergei
2018/01/30 17:28:24
Perhaps alternatively we could do it in `matchesUr
Thomas Greiner
2018/01/30 19:17:53
In theory that's correct but in practice this is n
sergei
2018/01/30 21:06:48
It does happen on practice (at least I observed th
kzar
2018/01/31 11:06:27
How about using the Prefs.untilLoaded Promise?
sergei
2018/02/05 12:49:34
It seems the best option.
| |
191 if (data) | 191 if (data) |
192 { | 192 { |
193 for (let notification of data.notifications) | 193 for (let notification of data.notifications) |
194 { | 194 { |
195 initNotificationMatcher(notification); | 195 initNotificationMatcher(notification); |
196 } | 196 } |
197 } | 197 } |
198 | 198 |
199 downloader = new Downloader(this._getDownloadables.bind(this), | 199 downloader = new Downloader(this._getDownloadables.bind(this), |
200 INITIAL_DELAY, CHECK_INTERVAL); | 200 INITIAL_DELAY, CHECK_INTERVAL); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 showListeners.splice(index, 1); | 303 showListeners.splice(index, 1); |
304 }, | 304 }, |
305 | 305 |
306 /** | 306 /** |
307 * Determines which notification is to be shown next. | 307 * Determines which notification is to be shown next. |
308 * @param {string} url URL to match notifications to (optional) | 308 * @param {string} url URL to match notifications to (optional) |
309 * @return {Object} notification to be shown, or null if there is none | 309 * @return {Object} notification to be shown, or null if there is none |
310 */ | 310 */ |
311 _getNextToShow(url) | 311 _getNextToShow(url) |
312 { | 312 { |
313 let remoteData = Prefs.notificationdata.data.notifications; | 313 let remoteData = []; |
314 if (typeof Prefs.notificationdata.data == "object" && | |
315 Prefs.notificationdata.data.notifications instanceof Array) | |
316 { | |
317 remoteData = Prefs.notificationdata.data.notifications; | |
318 } | |
314 let notifications = localData.concat(remoteData); | 319 let notifications = localData.concat(remoteData); |
315 if (notifications.length === 0) | 320 if (notifications.length === 0) |
316 return null; | 321 return null; |
317 | 322 |
318 const {addonName, addonVersion, application, | 323 const {addonName, addonVersion, application, |
319 applicationVersion, platform, platformVersion} = require("info"); | 324 applicationVersion, platform, platformVersion} = require("info"); |
320 | 325 |
321 let targetChecks = { | 326 let targetChecks = { |
322 extension: v => v == addonName, | 327 extension: v => v == addonName, |
323 extensionMinVersion: | 328 extensionMinVersion: |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 else if (index != -1 && forceValue !== true) | 562 else if (index != -1 && forceValue !== true) |
558 categories.splice(index, 1); | 563 categories.splice(index, 1); |
559 | 564 |
560 // HACK: JSON values aren't saved unless they are assigned a | 565 // HACK: JSON values aren't saved unless they are assigned a |
561 // different object. | 566 // different object. |
562 Prefs.notifications_ignoredcategories = | 567 Prefs.notifications_ignoredcategories = |
563 JSON.parse(JSON.stringify(categories)); | 568 JSON.parse(JSON.stringify(categories)); |
564 } | 569 } |
565 }; | 570 }; |
566 Notification.init(); | 571 Notification.init(); |
LEFT | RIGHT |