Skip to content

Commit

Permalink
Keep the add-ons manager UI up to date as script versions change.
Browse files Browse the repository at this point in the history
Fixes #1710
  • Loading branch information
arantius committed Apr 25, 2013
1 parent 8578882 commit c12cbf2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 10 additions & 2 deletions content/addons4-overlay.js
Expand Up @@ -9,6 +9,7 @@ Components.utils.import('resource://greasemonkey/util.js');

var userScriptViewId = 'addons://list/greasemonkey-user-script';

window.addEventListener('focus', focus, false);
window.addEventListener('load', init, false);
window.addEventListener('unload', unload, false);

Expand Down Expand Up @@ -67,8 +68,7 @@ var observer = {
if (!data) break;
var oldAddon = ScriptAddonFactoryByScript({'id': data});
if (!oldAddon) break;
ScriptAddonReplaceScript(script);
addon = ScriptAddonFactoryByScript(script);
addon = ScriptAddonReplaceScript(script);

// Use the addon references to update the view to match the new state.
var item = createItem(addon);
Expand Down Expand Up @@ -111,6 +111,14 @@ function sortedByExecOrder() {
.hasAttribute('checkState');
};

function focus() {
// When the window gains focus, it might be from switching to an editor
// and back, so scan for updated scripts.
var config = GM_util.getService().config;
config.updateModifiedScripts('document-start', null);
config.updateModifiedScripts('document-end', null);
}

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

Expand Down
9 changes: 8 additions & 1 deletion modules/script.js
Expand Up @@ -526,6 +526,10 @@ Script.prototype.isRemoteUpdateAllowed = function() {
};

Script.prototype.updateFromNewScript = function(newScript, safeWin) {
// Keep a _copy_ of the old script ID, so we can eventually pass it up
// to the Add-ons manager UI, to update this script's old entry.
var oldScriptId = '' + this.id;

// If the @name and/or @namespace have changed, make sure they don't
// conflict with another installed script.
if (newScript.id != this.id) {
Expand Down Expand Up @@ -574,6 +578,9 @@ Script.prototype.updateFromNewScript = function(newScript, safeWin) {
this.showGrantWarning();
this.checkConfig();

// Update add-ons manager UI.
this._changed('modified', oldScriptId);

var dependhash = GM_util.sha1(newScript._rawMeta);
if (dependhash != this._dependhash && !newScript._dependFail) {
// Store window references for late injection.
Expand All @@ -583,7 +590,7 @@ Script.prototype.updateFromNewScript = function(newScript, safeWin) {
true);
this.pendingExec.push('document-start update');
} else {
this.pendingExec.push({'safeWin': safeWin});
if (safeWin) this.pendingExec.push({'safeWin': safeWin});
}

// Re-download dependencies.
Expand Down

0 comments on commit c12cbf2

Please sign in to comment.