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 |
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 "use strict"; | 18 "use strict"; |
19 | 19 |
20 /** | 20 /** |
21 * @fileOverview Handles notifications. | 21 * @fileOverview Handles notifications. |
22 */ | 22 */ |
23 | 23 |
24 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | |
25 | |
26 const {Prefs} = require("prefs"); | 24 const {Prefs} = require("prefs"); |
27 const {Downloader, Downloadable, | 25 const {Downloader, Downloadable, |
28 MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader"); | 26 MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader"); |
29 const {Utils} = require("utils"); | 27 const {Utils} = require("utils"); |
30 const {Matcher, defaultMatcher} = require("matcher"); | 28 const {Matcher, defaultMatcher} = require("matcher"); |
31 const {Filter, RegExpFilter, WhitelistFilter} = require("filterClasses"); | 29 const {Filter, RegExpFilter, WhitelistFilter} = require("filterClasses"); |
32 | 30 |
33 const INITIAL_DELAY = 1 * MILLIS_IN_MINUTE; | 31 const INITIAL_DELAY = 1 * MILLIS_IN_MINUTE; |
34 const CHECK_INTERVAL = 1 * MILLIS_IN_HOUR; | 32 const CHECK_INTERVAL = 1 * MILLIS_IN_HOUR; |
35 const EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY; | 33 const EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY; |
(...skipping 26 matching lines...) Expand all Loading... | |
62 return translations[locale]; | 60 return translations[locale]; |
63 | 61 |
64 let languagePart = locale.substring(0, locale.indexOf("-")); | 62 let languagePart = locale.substring(0, locale.indexOf("-")); |
65 if (languagePart && languagePart in translations) | 63 if (languagePart && languagePart in translations) |
66 return translations[languagePart]; | 64 return translations[languagePart]; |
67 | 65 |
68 let defaultLocale = "en-US"; | 66 let defaultLocale = "en-US"; |
69 return translations[defaultLocale]; | 67 return translations[defaultLocale]; |
70 } | 68 } |
71 | 69 |
70 function compareVersion(v1, v2) | |
71 { | |
72 let regexp = /^(.*?)([a-z].*)?$/i; | |
Manish Jethani
2017/09/22 23:28:51
If "57.0a9" vs "57.0a10" matters, we could handle
Sebastian Noack
2017/09/23 00:32:50
This would add notable complexity to this implemen
| |
73 let [, head1, tail1] = regexp.exec(v1); | |
74 let [, head2, tail2] = regexp.exec(v2); | |
75 let components1 = head1.split("."); | |
76 let components2 = head2.split("."); | |
77 | |
78 for (let i = 0; i < components1.length || | |
79 i < components2.length; i++) | |
80 { | |
81 let comp1 = components1[i]; | |
82 let comp2 = components2[i]; | |
83 | |
84 let result = (comp1 == "*" ? Infinity : parseInt(comp1, 10) || 0) - | |
85 (comp2 == "*" ? Infinity : parseInt(comp2, 10) || 0) || 0; | |
Wladimir Palant
2017/09/22 10:11:49
The readability of this statement is very suboptim
Sebastian Noack
2017/09/23 00:32:50
I kinda liked the one-liner, but what I like about
| |
86 | |
87 if (result != 0) | |
88 return result; | |
89 } | |
90 | |
91 return tail1 == tail2 ? 0 : !tail1 || tail2 && tail1 > tail2 ? 1 : -1; | |
Wladimir Palant
2017/09/22 10:11:49
This part isn't covered by unit tests (so far thes
Manish Jethani
2017/09/22 23:23:41
FWIW "tail2 && tail1 > tail2" can be just "tail1 >
Sebastian Noack
2017/09/23 00:32:50
Done.
Sebastian Noack
2017/09/23 00:32:50
This is actually true (it wasn't in earlier when I
| |
92 } | |
93 | |
72 /** | 94 /** |
73 * The object providing actual downloading functionality. | 95 * The object providing actual downloading functionality. |
74 * @type {Downloader} | 96 * @type {Downloader} |
75 */ | 97 */ |
76 let downloader = null; | 98 let downloader = null; |
77 let localData = []; | 99 let localData = []; |
78 | 100 |
79 /** | 101 /** |
80 * Regularly fetches notifications and decides which to show. | 102 * Regularly fetches notifications and decides which to show. |
81 * @class | 103 * @class |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 let notifications = localData.concat(remoteData); | 232 let notifications = localData.concat(remoteData); |
211 if (notifications.length === 0) | 233 if (notifications.length === 0) |
212 return null; | 234 return null; |
213 | 235 |
214 const {addonName, addonVersion, application, | 236 const {addonName, addonVersion, application, |
215 applicationVersion, platform, platformVersion} = require("info"); | 237 applicationVersion, platform, platformVersion} = require("info"); |
216 | 238 |
217 let targetChecks = { | 239 let targetChecks = { |
218 extension: v => v == addonName, | 240 extension: v => v == addonName, |
219 extensionMinVersion: | 241 extensionMinVersion: |
220 v => Services.vc.compare(addonVersion, v) >= 0, | 242 v => compareVersion(addonVersion, v) >= 0, |
221 extensionMaxVersion: | 243 extensionMaxVersion: |
222 v => Services.vc.compare(addonVersion, v) <= 0, | 244 v => compareVersion(addonVersion, v) <= 0, |
223 application: v => v == application, | 245 application: v => v == application, |
224 applicationMinVersion: | 246 applicationMinVersion: |
225 v => Services.vc.compare(applicationVersion, v) >= 0, | 247 v => compareVersion(applicationVersion, v) >= 0, |
226 applicationMaxVersion: | 248 applicationMaxVersion: |
227 v => Services.vc.compare(applicationVersion, v) <= 0, | 249 v => compareVersion(applicationVersion, v) <= 0, |
228 platform: v => v == platform, | 250 platform: v => v == platform, |
229 platformMinVersion: | 251 platformMinVersion: |
230 v => Services.vc.compare(platformVersion, v) >= 0, | 252 v => compareVersion(platformVersion, v) >= 0, |
231 platformMaxVersion: | 253 platformMaxVersion: |
232 v => Services.vc.compare(platformVersion, v) <= 0, | 254 v => compareVersion(platformVersion, v) <= 0, |
233 blockedTotalMin: v => Prefs.show_statsinpopup && | 255 blockedTotalMin: v => Prefs.show_statsinpopup && |
234 Prefs.blocked_total >= v, | 256 Prefs.blocked_total >= v, |
235 blockedTotalMax: v => Prefs.show_statsinpopup && | 257 blockedTotalMax: v => Prefs.show_statsinpopup && |
236 Prefs.blocked_total <= v, | 258 Prefs.blocked_total <= v, |
237 locales: v => v.includes(Utils.appLocale) | 259 locales: v => v.includes(Utils.appLocale) |
238 }; | 260 }; |
239 | 261 |
240 let notificationToShow = null; | 262 let notificationToShow = null; |
241 for (let notification of notifications) | 263 for (let notification of notifications) |
242 { | 264 { |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
481 else if (index != -1 && forceValue !== true) | 503 else if (index != -1 && forceValue !== true) |
482 categories.splice(index, 1); | 504 categories.splice(index, 1); |
483 | 505 |
484 // HACK: JSON values aren't saved unless they are assigned a | 506 // HACK: JSON values aren't saved unless they are assigned a |
485 // different object. | 507 // different object. |
486 Prefs.notifications_ignoredcategories = | 508 Prefs.notifications_ignoredcategories = |
487 JSON.parse(JSON.stringify(categories)); | 509 JSON.parse(JSON.stringify(categories)); |
488 } | 510 } |
489 }; | 511 }; |
490 Notification.init(); | 512 Notification.init(); |
OLD | NEW |