Skip to content

Commit

Permalink
Remove GM_getConfig().
Browse files Browse the repository at this point in the history
GM_util.getService().config works just fine.
  • Loading branch information
Anthony Lieuallen committed Aug 22, 2011
1 parent 7a81c59 commit 0677a1e
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion content/addons.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Components.utils.import('resource://greasemonkey/util.js');

// Globals.
var GM_config = GM_getConfig();
var GM_config = GM_util.getService().config;
var GM_uninstallQueue = {};
var gUserscriptsView = null;

Expand Down
11 changes: 6 additions & 5 deletions content/addons4-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ function addonExecutesNonFirst(aAddon) {
function addonExecutesNonLast(aAddon) {
if (!aAddon) return false;
if (SCRIPT_ADDON_TYPE != aAddon.type) return false;
return GM_getConfig().scripts.length - 1 != aAddon.executionIndex;
return (GM_util.getService().config.scripts.length - 1)
!= aAddon.executionIndex;
}

function sortedByExecOrder() {
Expand All @@ -95,7 +96,7 @@ function sortedByExecOrder() {
};

function init() {
GM_getConfig().addObserver(observer);
GM_util.getService().config.addObserver(observer);

gViewController.commands.cmd_userscript_edit = {
isEnabled: addonIsInstalledScript,
Expand Down Expand Up @@ -185,7 +186,7 @@ function onViewChanged(aEvent) {

function setEmptyWarningVisible() {
var emptyWarning = document.getElementById('user-script-list-empty');
emptyWarning.collapsed = !!GM_getConfig().scripts.length;
emptyWarning.collapsed = !!GM_util.getService().config.scripts.length;
}

function selectScriptExecOrder() {
Expand All @@ -199,7 +200,7 @@ function selectScriptExecOrder() {

function reorderScriptExecution(aAddon, moveBy) {
selectScriptExecOrder();
GM_getConfig().move(aAddon._script, moveBy);
GM_util.getService().config.move(aAddon._script, moveBy);
AddonManager.getAddonsByTypes([SCRIPT_ADDON_TYPE], function(aAddons) {
// Fix all the 'executionOrder' attributes.
for (var i = 0, addon = null; addon = aAddons[i]; i++) {
Expand All @@ -220,7 +221,7 @@ function setRichlistitemExecutionIndex(aAddon) {
};

function unload() {
var GM_config = GM_getConfig();
var GM_config = GM_util.getService().config;
// Since .getAddonsByTypes() is asynchronous, AddonManager gets destroyed
// by the time the callback runs. Cache this value we need from it.
var pending_uninstall = AddonManager.PENDING_UNINSTALL;
Expand Down
4 changes: 2 additions & 2 deletions content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ GM_BrowserUI.installCurrentScript = function() {
};

GM_BrowserUI.installScript = function(script){
GM_getConfig().install(script);
GM_util.getService().config.install(script);

var tools = {};
Components.utils.import("resource://greasemonkey/GM_notification.js", tools);
Expand Down Expand Up @@ -368,7 +368,7 @@ function GM_showPopup(aEvent) {
}
return urls.some(testMatchURL);
}
return GM_getConfig().getMatchingScripts(testMatchURLs);
return GM_util.getService().config.getMatchingScripts(testMatchURLs);
}

function appendScriptAfter(script, point) {
Expand Down
2 changes: 1 addition & 1 deletion content/newscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ window.addEventListener("load", function window_load() {
function doInstall() {
var scriptSrc = createScriptSource();
if (!scriptSrc) return false;
var config = GM_getConfig();
var config = GM_util.getService().config;

// Create a script object with parsed metadata, and ...
var script = config.parse(scriptSrc);
Expand Down
4 changes: 2 additions & 2 deletions content/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ function GM_loadOptions() {
document.getElementById("check-uninstall")
.checked = GM_prefRoot.getValue("uninstallPreferences");
document.getElementById("globalExcludes")
.pages = GM_getConfig().globalExcludes;
.pages = GM_util.getService().config.globalExcludes;
}

function GM_saveOptions(checkbox) {
GM_prefRoot.setValue("uninstallPreferences",
!!document.getElementById("check-uninstall").checked);
GM_getConfig().globalExcludes =
GM_util.getService().config.globalExcludes =
document.getElementById("globalExcludes").pages;
}
12 changes: 6 additions & 6 deletions content/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Script.prototype.matchesURL = function(url) {

// Flat deny if URL is not greaseable, or matches global excludes.
if (!GM_util.isGreasemonkeyable(url)) return false;
if (GM_getConfig()._globalExcludes.some(testClude)) return false;
if (GM_util.getService().config._globalExcludes.some(testClude)) return false;

// Allow based on user cludes.
if (this._userExcludes.some(testClude)) return false;
Expand All @@ -68,7 +68,7 @@ Script.prototype.matchesURL = function(url) {
};

Script.prototype._changed = function(event, data) {
GM_getConfig()._changed(this, event, data);
GM_util.getService().config._changed(this, event, data);
};

Script.prototype.__defineGetter__('modifiedDate',
Expand Down Expand Up @@ -218,14 +218,14 @@ Script.prototype._loadFromConfigNode = function(node) {
|| !node.hasAttribute("dependhash")
|| !node.hasAttribute("version")
) {
var parsedScript = GM_getConfig().parse(
var parsedScript = GM_util.getService().config.parse(
this.textContent, GM_uriFromUrl(this._downloadURL), !!this);

this._modified = this.file.lastModifiedTime;
this._dependhash = GM_util.sha1(parsedScript._rawMeta);
this._version = parsedScript._version;

GM_getConfig()._changed(this, "modified", null);
GM_util.getService().config._changed(this, "modified", null);
} else {
this._modified = node.getAttribute("modified");
this._dependhash = node.getAttribute("dependhash");
Expand Down Expand Up @@ -399,7 +399,7 @@ Script.prototype.updateFromNewScript = function(newScript, safeWin, chromeWin) {
// if the @name and @namespace have changed
// make sure they don't conflict with another installed script
if (newScript.id != this.id) {
if (!GM_getConfig().installIsUpdate(newScript)) {
if (!GM_util.getService().config.installIsUpdate(newScript)) {
// Migrate preferences.
if (this.prefroot != newScript.prefroot) {
var storageOld = new GM_ScriptStorage(this);
Expand Down Expand Up @@ -512,5 +512,5 @@ Script.prototype.uninstall = function(forUpdate) {
GM_prefRoot.remove(this.prefroot);
}

GM_getConfig()._changed(this, "uninstall", null);
GM_util.getService().config._changed(this, "uninstall", null);
};
5 changes: 3 additions & 2 deletions content/scriptdownloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ GM_ScriptDownloader.prototype.handleScriptDownloadComplete = function() {

var source = this.req_.responseText;

this.script = GM_getConfig().parse(source, this.uri_);
this.script = GM_util.getService().config.parse(source, this.uri_);

var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
Expand Down Expand Up @@ -280,7 +280,8 @@ GM_ScriptDownloader.prototype.finishInstall = function() {
}

// Save new values to config.xml
GM_getConfig()._changed(this.script, "modified", this._oldScriptId, true);
GM_util.getService().config._changed(
this.script, "modified", this._oldScriptId, true);
} else if (this.installOnCompletion_) {
this.installScript();
}
Expand Down
4 changes: 2 additions & 2 deletions content/scriptprefs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Components.utils.import('resource://greasemonkey/util.js'); // ref'd in XUL

var gScriptId = location.hash.substring(1);
var gScript = GM_getConfig().getMatchingScripts(function(script) {
var gScript = GM_util.getService().config.getMatchingScripts(function(script) {
return script.id == gScriptId;
})[0];

Expand Down Expand Up @@ -44,5 +44,5 @@ function onDialogAccept() {
gScript.userIncludes = gUserIncludesEl.pages;
gScript.excludes = gScriptExcludesEl.pages;
gScript.userExcludes = gUserExcludesEl.pages;
GM_getConfig()._changed(gScript, "cludes");
GM_util.getService().config._changed(gScript, "cludes");
}
4 changes: 0 additions & 4 deletions content/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@ Components.utils.import('resource://greasemonkey/prefmanager.js');
Components.utils.import('resource://greasemonkey/util.js');
// Load module-ized methods here for legacy access.
Components.utils.import("resource://greasemonkey/utils.js");

function GM_getConfig() {
return GM_util.getService().config;
}
12 changes: 6 additions & 6 deletions modules/addons4.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ var SCRIPT_ID_SUFFIX = '@greasespot.net';
var SCRIPT_ADDON_TYPE = 'user-script';

// Pull this helper method into this module scope; it's not module-ized yet.
var GM_getConfig;
var GM_util.getService().config;
(function() {
var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var scope = {};
loader.loadSubScript('chrome://greasemonkey/content/utils.js', scope);
GM_getConfig = scope.GM_getConfig;
GM_util.getService().config = scope.GM_util.getService().config;
})();

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -48,7 +48,7 @@ var AddonProvider = {
aCallback([]);
} else {
var scriptAddons = [];
GM_getConfig().scripts.forEach(function(script) {
GM_util.getService().config.scripts.forEach(function(script) {
scriptAddons.push(ScriptAddonFactoryByScript(script));
});
aCallback(scriptAddons);
Expand All @@ -65,7 +65,7 @@ function ScriptAddonFactoryByScript(aScript) {
return ScriptAddonCache[id];
}
function ScriptAddonFactoryById(aId) {
var scripts = GM_getConfig().getMatchingScripts(
var scripts = GM_util.getService().config.getMatchingScripts(
function(script) {
return (script.id + SCRIPT_ID_SUFFIX) == aId;
});
Expand Down Expand Up @@ -114,7 +114,7 @@ ScriptAddon.prototype._script = null;

ScriptAddon.prototype.__defineGetter__('executionIndex',
function ScriptAddon_getExecutionIndex() {
return GM_getConfig()._scripts.indexOf(this._script);
return GM_util.getService().config._scripts.indexOf(this._script);
});

// Getters/setters/functions for API attributes.
Expand Down Expand Up @@ -184,7 +184,7 @@ ScriptAddon.prototype.cancelUninstall = function() {
};

ScriptAddon.prototype.performUninstall = function() {
GM_getConfig().uninstall(this._script);
GM_util.getService().config.uninstall(this._script);
delete ScriptAddonCache[this.id];
};

Expand Down

0 comments on commit 0677a1e

Please sign in to comment.