| Index: lib/notification.js |
| =================================================================== |
| --- a/lib/notification.js |
| +++ b/lib/notification.js |
| @@ -21,8 +21,6 @@ |
| * @fileOverview Handles notifications. |
| */ |
| -const {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
| - |
| const {Prefs} = require("prefs"); |
| const {Downloader, Downloadable, |
| MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader"); |
| @@ -69,6 +67,30 @@ |
| return translations[defaultLocale]; |
| } |
| +function compareVersion(v1, v2) |
| +{ |
| + 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
|
| + let [, head1, tail1] = regexp.exec(v1); |
| + let [, head2, tail2] = regexp.exec(v2); |
| + let components1 = head1.split("."); |
| + let components2 = head2.split("."); |
| + |
| + for (let i = 0; i < components1.length || |
| + i < components2.length; i++) |
| + { |
| + let comp1 = components1[i]; |
| + let comp2 = components2[i]; |
| + |
| + let result = (comp1 == "*" ? Infinity : parseInt(comp1, 10) || 0) - |
| + (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
|
| + |
| + if (result != 0) |
| + return result; |
| + } |
| + |
| + 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
|
| +} |
| + |
| /** |
| * The object providing actual downloading functionality. |
| * @type {Downloader} |
| @@ -217,19 +239,19 @@ |
| let targetChecks = { |
| extension: v => v == addonName, |
| extensionMinVersion: |
| - v => Services.vc.compare(addonVersion, v) >= 0, |
| + v => compareVersion(addonVersion, v) >= 0, |
| extensionMaxVersion: |
| - v => Services.vc.compare(addonVersion, v) <= 0, |
| + v => compareVersion(addonVersion, v) <= 0, |
| application: v => v == application, |
| applicationMinVersion: |
| - v => Services.vc.compare(applicationVersion, v) >= 0, |
| + v => compareVersion(applicationVersion, v) >= 0, |
| applicationMaxVersion: |
| - v => Services.vc.compare(applicationVersion, v) <= 0, |
| + v => compareVersion(applicationVersion, v) <= 0, |
| platform: v => v == platform, |
| platformMinVersion: |
| - v => Services.vc.compare(platformVersion, v) >= 0, |
| + v => compareVersion(platformVersion, v) >= 0, |
| platformMaxVersion: |
| - v => Services.vc.compare(platformVersion, v) <= 0, |
| + v => compareVersion(platformVersion, v) <= 0, |
| blockedTotalMin: v => Prefs.show_statsinpopup && |
| Prefs.blocked_total >= v, |
| blockedTotalMax: v => Prefs.show_statsinpopup && |