Skip to content

Commit

Permalink
Added an observer so changes to scripts outside of the Addons manager…
Browse files Browse the repository at this point in the history
… are used to update the Addon objects with the changes and then reload the mangager so these changes are visible. Closes greasemonkey#1305
  • Loading branch information
sizzlemctwizzle authored and arantius committed Mar 13, 2011
1 parent d1d668d commit a480fe9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
24 changes: 24 additions & 0 deletions content/addons4-overlay.js
Expand Up @@ -25,6 +25,26 @@ createItem = function GM_createItem(aObj, aIsInstall, aIsRemote) {
return item;
};

// Set up an "observer" on the config, to keep the displayed items up to date
// with their actual state.
var observer = {
notifyEvent: function(script, event, data) {
if ('addons://list/user-script' != gViewController.currentViewId) return;

switch (event) {
case 'install':
case 'modified':
ScriptAddonReplaceScript(script);
break;
case "edit-enabled":
ScriptAddonFactoryByScript(script).userDisabled = !data;
break;
}

gViewController.loadViewInternal('addons://list/user-script', null);
}
};

// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //

function addonIsInstalledScript(aAddon) {
Expand All @@ -35,6 +55,8 @@ function addonIsInstalledScript(aAddon) {
};

function init() {
GM_getConfig().addObserver(observer);

gViewController.commands.cmd_userscript_edit = {
isEnabled: addonIsInstalledScript,
doCommand: function(aAddon) { GM_openInEditor(aAddon._script); }
Expand Down Expand Up @@ -170,5 +192,7 @@ function unload() {
// Todo: This without dipping into private members.
GM_config._save(true);
});

GM_config.removeObserver(observer);
};
})();
7 changes: 5 additions & 2 deletions modules/addons4.js
Expand Up @@ -6,7 +6,7 @@
// http://www.oxymoronical.com/blog/2010/07/How-to-extend-the-new-Add-ons-Manager

// Module exported symbols.
var EXPORTED_SYMBOLS = ['GM_addonsStartup'];
var EXPORTED_SYMBOLS = ['GM_addonsStartup', 'ScriptAddonFactoryByScript', 'ScriptAddonReplaceScript'];

////////////////////////////////////////////////////////////////////////////////
// Module level imports / constants / globals.
Expand Down Expand Up @@ -70,7 +70,10 @@ function ScriptAddonFactoryById(aId) {
// TODO: throw an error instead?
return null;
}

function ScriptAddonReplaceScript(aScript) {
var id = aScript.id + SCRIPT_ID_SUFFIX;
ScriptAddonCache[id] = new ScriptAddon(aScript);
}

// https://developer.mozilla.org/en/Addons/Add-on_Manager/Addon
function ScriptAddon(aScript) {
Expand Down

0 comments on commit a480fe9

Please sign in to comment.