Skip to content

Commit

Permalink
Show working progress bar in AOM updates.
Browse files Browse the repository at this point in the history
Fixes #1419
  • Loading branch information
Anthony Lieuallen committed Dec 2, 2011
1 parent b3f8572 commit 30eda66
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
21 changes: 6 additions & 15 deletions content/script.js
Expand Up @@ -551,7 +551,7 @@ Script.prototype.checkRemoteVersion = function(req, aCallback) {
if (req.status != 200 && req.status != 0) return aCallback(false);

var source = req.responseText;
var newScript = GM_util.getService().config.parse(source);
var newScript = GM_util.getService().config.parse(source, this._downloadURL);
var remoteVersion = newScript.version;
if (!remoteVersion) return aCallback(false);

Expand Down Expand Up @@ -607,29 +607,20 @@ Script.prototype.handleRemoteUpdate = function(aAvailable, aListener) {
}
}

Script.prototype.installUpdate = function(aChromeWin, aCallback) {
Script.prototype.installUpdate = function(aProgressCallback) {
var oldScriptId = new String(this.id);
function updateAddons(aNewScript) {
// Timeout puts this update after core code has removed the download
// progress bar. It causes an open add-ons manager to be updated with the
// new script details (version, primarily).
GM_util.timeout(
0, function() {
aCallback();
GM_util.getService().config._changed(
aNewScript, 'modified', oldScriptId);
});
}

var scope = {};
Components.utils.import('resource://greasemonkey/remoteScript.js', scope);
var rs = new scope.RemoteScript(this._downloadURL);
if (aProgressCallback) rs.onProgress(aProgressCallback);
rs.download(GM_util.hitch(this, function(aSuccess, aType) {
if (aSuccess && 'dependencies' == aType) {
rs.install(this);
updateAddons(rs.script);
aProgressCallback(rs, 'progress', 1);
GM_util.getService().config._changed(rs.script, 'modified', oldScriptId);
}
}));
return rs;
};

Script.prototype.allFiles = function() {
Expand Down
51 changes: 35 additions & 16 deletions modules/addons4.js
Expand Up @@ -54,7 +54,7 @@ var AddonProvider = {
if (!script.updateAvailable) return;

var aAddon = ScriptAddonFactoryByScript(script);
var scriptInstall = aAddon._installer || new ScriptInstall(aAddon);
var scriptInstall = ScriptInstallFactoryByAddon(aAddon);

scriptInstalls.push(scriptInstall);
});
Expand Down Expand Up @@ -118,7 +118,6 @@ ScriptAddon.prototype.description = null;

// Private and custom attributes.
ScriptAddon.prototype._script = null;
ScriptAddon.prototype._installer = null;

ScriptAddon.prototype.__defineGetter__('executionIndex',
function ScriptAddon_getExecutionIndex() {
Expand Down Expand Up @@ -180,15 +179,15 @@ ScriptAddon.prototype.toString = function() {
};

ScriptAddon.prototype.uninstall = function() {
AddonManagerPrivate.callAddonListeners("onUninstalling", this, false);
AddonManagerPrivate.callAddonListeners('onUninstalling', this, false);
// TODO: pick an appropriate time, and act on these pending uninstalls.
this.pendingOperations |= AddonManager.PENDING_UNINSTALL;
AddonManagerPrivate.callAddonListeners("onUninstalled", this);
AddonManagerPrivate.callAddonListeners('onUninstalled', this);
};

ScriptAddon.prototype.cancelUninstall = function() {
this.pendingOperations ^= AddonManager.PENDING_UNINSTALL;
AddonManagerPrivate.callAddonListeners("onOperationCancelled", this);
AddonManagerPrivate.callAddonListeners('onOperationCancelled', this);
};

ScriptAddon.prototype.performUninstall = function() {
Expand All @@ -208,21 +207,21 @@ function ScriptInstallFactoryByAddon(aAddon) {

function ScriptInstall(aAddon) {
this._script = aAddon._script;
aAddon._installer = this;

this.name = this._script.name;
this.version = this._script.version;
this.iconURL = this._script.icon.fileURL;
this.existingAddon = aAddon;

this._listeners = [];
}

// Required attributes.
ScriptInstall.prototype.addon = null;
ScriptInstall.prototype.error = null;
ScriptInstall.prototype.file = null;
ScriptInstall.prototype.maxProgress = -1;
ScriptInstall.prototype.pendingOperations = 0;
ScriptInstall.prototype.progress = -1;
ScriptInstall.prototype.progress = 0;
ScriptInstall.prototype.releaseNotesURI = null;
ScriptInstall.prototype.sourceURI = null;
ScriptInstall.prototype.state = AddonManager.STATE_AVAILABLE;
Expand All @@ -232,19 +231,39 @@ ScriptInstall.prototype.type = 'user-script';
ScriptInstall.prototype._script = null;

ScriptInstall.prototype.install = function() {
function installCallback() {
AddonManagerPrivate.callAddonListeners(
'onInstallEnded', this, this.existingAddon);
function progressCallback(aRemoteScript, aType, aData) {
this.maxProgress = 100;
this.progress = Math.floor(aData * 100);
AddonManagerPrivate.callInstallListeners(
'onDownloadProgress', this._listeners, this);
}

AddonManagerPrivate.callAddonListeners('onInstallStarted', this);
var chromeWin = GM_util.getBrowserWindow();
this._script.installUpdate(chromeWin, GM_util.hitch(this, installCallback));
this.state = AddonManager.STATE_DOWNLOADING;
this._remoteScript = this._script.installUpdate(
GM_util.hitch(this, progressCallback));
};

ScriptInstall.prototype.cancel = function() {
this.state = AddonManager.STATE_AVAILABLE;
AddonManagerPrivate.callAddonListeners(
'onInstallEnded', this, this.existingAddon);
if (this._remoteScript) {
this._remoteScript.cleanup();
this._remoteScript = null;
}
};

ScriptInstall.prototype.cancel = function() {};
ScriptInstall.prototype.addListener = function() {};
ScriptInstall.prototype.removeListener = function() {};
ScriptInstall.prototype.addListener = function AI_addListener(aListener) {
if (!this._listeners.some(function(i) { return i == aListener; })) {
this._listeners.push(aListener);
}
};

ScriptInstall.prototype.removeListener = function AI_removeListener(aListener) {
this._listeners =
this._listeners.filter(function(i) { return i != aListener; });
};

ScriptInstall.prototype.toString = function() {
return '[ScriptInstall object ' + this._script.id + ']';
Expand Down

0 comments on commit 30eda66

Please sign in to comment.