Permalink
Browse files

Store preferences under "extensions.greasemonkey.".

Fixes #1652
  • Loading branch information...
1 parent 9777bb4 commit 89dcdf96bd69282d2a443a4f82281f254493adc2 @arantius arantius committed Oct 24, 2012
Showing with 59 additions and 17 deletions.
  1. +8 −0 content/browser.js
  2. +39 −6 content/config.js
  3. +11 −10 defaults/preferences/greasemonkey.js
  4. +1 −1 modules/prefmanager.js
View
@@ -203,6 +203,14 @@ GM_BrowserUI.viewContextItemClicked = function() {
};
GM_BrowserUI.showToolbarButton = function() {
+ // See #1652. During transition, this might be set, but not readable yet;
+ // transition happens in an async callback to get addon version. If existing
+ // version is "0.0" (the default), this hasn't happened yet, so try later.
+ if ('0.0' == GM_prefRoot.getValue("version")) {
+ setTimeout(GM_BrowserUI.showToolbarButton, 50);
+ return;
+ }
+
// Once, enforce that the toolbar button is present. For discoverability.
if (!GM_prefRoot.getValue('haveInsertedToolbarbutton')) {
GM_prefRoot.setValue('haveInsertedToolbarbutton', true);
View
@@ -256,16 +256,29 @@ Config.prototype.getScriptById = function(scriptId) {
* any necessary upgrades.
*/
Config.prototype._updateVersion = function() {
- var initialized = GM_prefRoot.getValue("version", "0.0");
-
Components.utils.import("resource://gre/modules/AddonManager.jsm");
- AddonManager.getAddonByID(this.GM_GUID, function(addon) {
+ AddonManager.getAddonByID(this.GM_GUID, GM_util.hitch(this, function(addon) {
+ var oldVersion = GM_prefRoot.getValue("version");
+ if ('0.0' == oldVersion) {
+ // In case of pref branch transition, find the existing version there.
+ oldVersion = this._getLegacyPrefMan().getValue("version", "0.0");
+ }
var newVersion = addon.version;
- // Update the currently initialized version so we don't do this work again.
+ var versionChecker = Components
+ .classes["@mozilla.org/xpcom/version-comparator;1"]
+ .getService(Components.interfaces.nsIVersionComparator);
+ if (oldVersion != '0.0'
+ && (versionChecker.compare(oldVersion, '1.5') < 0)
+ && (versionChecker.compare(newVersion, '1.5') >= 0)
+ ) {
+ this._migratePrefs();
+ }
+
+ // Update the stored current version so we don't do this work again.
GM_prefRoot.setValue("version", newVersion);
- if ("0.0" == initialized) {
+ if ("0.0" == oldVersion) {
// This is the first launch. Show the welcome screen.
var chromeWin = GM_util.getBrowserWindow();
// If we found it, use it to open a welcome tab.
@@ -276,5 +289,25 @@ Config.prototype._updateVersion = function() {
chromeWin.setTimeout(chromeWin.GM_BrowserUI.openTab, 0, url);
}
}
- });
+ }));
+};
+
+Config.prototype._getLegacyPrefMan = function() {
+ // Supports #1652.
+ var legacyPrefMan = new GM_PrefManager();
+ legacyPrefMan.pref = Components.classes["@mozilla.org/preferences-service;1"]
+ .getService(Components.interfaces.nsIPrefService)
+ .getBranch('greasemonkey.');
+ return legacyPrefMan;
+};
+
+Config.prototype._migratePrefs = function() {
+ // See #1652. Migrates from "greasemonkey." to "extensions.greasemonkey.".
+ var fromBranch = this._getLegacyPrefMan();
+ var toBranch = GM_prefRoot;
+ var prefNames = fromBranch.listValues();
+ for (var i = 0, prefName = null; prefName = prefNames[i]; i++) {
+ toBranch.setValue(prefName, fromBranch.getValue(prefName));
+ fromBranch.remove(prefName);
+ }
};
@@ -1,11 +1,12 @@
pref("extensions.{e4a8a97b-f2ed-450b-b12d-ee082ba24781}.description", "chrome://greasemonkey/locale/greasemonkey.properties");
-pref("greasemonkey.fileIsGreaseable", false);
-pref("greasemonkey.globalExcludes", '[]');
-pref("greasemonkey.installDelay", 5);
-pref("greasemonkey.unmhtIsGreaseable", false);
-pref("greasemonkey.enableScriptRefreshing", true);
-pref("greasemonkey.uninstallPreferences", true);
-pref("greasemonkey.requireSecureUpdates", true);
-pref("greasemonkey.haveInsertedToolbarbutton", false);
-pref("greasemonkey.logChrome", false);
-pref("greasemonkey.showGrantsWarning", true);
+pref("extensions.greasemonkey.enableScriptRefreshing", true);
+pref("extensions.greasemonkey.fileIsGreaseable", false);
+pref("extensions.greasemonkey.globalExcludes", '[]');
+pref("extensions.greasemonkey.haveInsertedToolbarbutton", false);
+pref("extensions.greasemonkey.installDelay", 5);
+pref("extensions.greasemonkey.logChrome", false);
+pref("extensions.greasemonkey.requireSecureUpdates", true);
+pref("extensions.greasemonkey.showGrantsWarning", true);
+pref("extensions.greasemonkey.uninstallPreferences", true);
+pref("extensions.greasemonkey.unmhtIsGreaseable", false);
+pref("extensions.greasemonkey.version", "0.0");
View
@@ -6,7 +6,7 @@ const EXPORTED_SYMBOLS = ['GM_PrefManager', 'GM_prefRoot'];
* "greasemonkey." prefix is assumed.
*/
function GM_PrefManager(startPoint) {
- startPoint = "greasemonkey." + (startPoint || "");
+ startPoint = "extensions.greasemonkey." + (startPoint || "");
this.pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)

0 comments on commit 89dcdf9

Please sign in to comment.