From fb6eec74d2f1bf050d068e0894cce89a31fc9a78 Mon Sep 17 00:00:00 2001 From: papush Date: Sun, 29 Aug 2021 14:54:20 +0200 Subject: figure out the add-on version programatically in handleUpgrades --- chrome/js/redirector.js | 73 ++++++++++++++++++++++++++----------------------- 1 file 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) { -- cgit v1.2.3-70-g09d2