| 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,40 @@ |
| return translations[defaultLocale]; |
| } |
| +function parseVersionComponent(comp) |
| +{ |
| + if (comp == "*") |
| + return Infinity; |
| + return parseInt(comp, 10) || 0; |
| +} |
| + |
| +function compareVersion(v1, v2) |
| +{ |
| + let regexp = /^(.*?)([a-z].*)?$/i; |
| + 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 result = parseVersionComponent(components1[i]) - |
| + parseVersionComponent(components2[i]) || 0; |
| + |
| + if (result != 0) |
| + return result; |
| + } |
| + |
| + // Compare version suffix (e.g. 0.1alpha < 0.1b1 < 01.b2 < 0.1). |
| + // However, note that this is a simple string comparision, meaning: b10 < b2 |
| + if (tail1 == tail2) |
| + return 0; |
| + if (!tail1 || tail2 && tail1 > tail2) |
| + return 1; |
| + return -1; |
| +} |
| + |
| /** |
| * The object providing actual downloading functionality. |
| * @type {Downloader} |
| @@ -217,19 +249,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 && |