aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpapush2021-08-29 14:54:20 +0200
committerpapush2021-08-29 14:55:10 +0200
commitfb6eec74d2f1bf050d068e0894cce89a31fc9a78 (patch)
tree8a950106c89f4f9aa21179730f46e52e5478d2f9
parent2635cf1cdf6448bd6990bcc2b2928145552cb382 (diff)
figure out the add-on version programatically in handleUpgrades
-rw-r--r--chrome/js/redirector.js73
1 files changed, 39 insertions, 34 deletions
diff --git a/chrome/js/redirector.js b/chrome/js/redirector.js
index fa48d68..b62c3da 100644
--- a/chrome/js/redirector.js
+++ b/chrome/js/redirector.js
@@ -2,6 +2,7 @@ Components.utils.import("chrome://redirector/content/js/xpcom.js");
Components.utils.import("chrome://redirector/content/js/redirect.js");
Components.utils.import("chrome://redirector/content/js/redirectorprefs.js");
Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import('resource://gre/modules/AddonManager.jsm');
var EXPORTED_SYMBOLS = ['Redirector'];
@@ -104,43 +105,47 @@ Redirector = {
return file;
},
- handleUpgrades : function(){
- var currentVersion = '2.8.3';
- this._list = [];
-
- if (this._prefs.version == currentVersion) {
- return;
- }
- //Here update checks are handled
+ handleUpgrades : function() {
+ AddonManager.getAddonByID("url-rewriter@papush", (addon) => {
+ currentVersion = '' + addon.version;
+ this._list = [];
- try {
- var branch = PrefService.getBranch("extensions.redirector.");
- var data = branch.getCharPref("redirects");
- } catch(e) {
- this._prefs.version = currentVersion;
- return;
- }
- var arr;
- this._list = [];
- if (data != '') {
- for each (redirectString in data.split(':::')) {
- if (!redirectString || !redirectString.split) {
- continue;
- this.debug('Invalid old redirect: ' + redirectString);
- }
- var parts = redirectString.split(',,,');
- if (parts.length < 5) {
- throw Error("Invalid serialized redirect, too few fields: " + redirectString);
+ if (this._prefs.version == currentVersion) {
+ this.debug("No version change, prefs migration skipped");
+ return;
+ }
+ this.debug("Migrating prefs");
+ //Here update checks are handled
+
+ try {
+ var branch = PrefService.getBranch("extensions.redirector.");
+ var data = branch.getCharPref("redirects");
+ } catch(e) {
+ this._prefs.version = currentVersion;
+ return;
+ }
+ var arr;
+ this._list = [];
+ if (data != '') {
+ for each (redirectString in data.split(':::')) {
+ if (!redirectString || !redirectString.split) {
+ continue;
+ this.debug('Invalid old redirect: ' + redirectString);
+ }
+ var parts = redirectString.split(',,,');
+ if (parts.length < 5) {
+ throw Error("Invalid serialized redirect, too few fields: " + redirectString);
+ }
+ var redirect = new Redirect();
+ redirect._init.apply(redirect, parts);
+ this._list.push(redirect);
}
- var redirect = new Redirect();
- redirect._init.apply(redirect, parts);
- this._list.push(redirect);
+ this.save();
+ this._list = []; //Let the real loading start this properly
}
- this.save();
- this._list = []; //Let the real loading start this properly
- }
- branch.deleteBranch('redirects');
- this._prefs.version = currentVersion;
+ branch.deleteBranch('redirects');
+ this._prefs.version = currentVersion;
+ });
},
importRedirects : function(file) {