Skip to content
Browse files

Check for remote updates works.

  • Loading branch information...
1 parent c7ce9b7 commit 5ded763651bac071be4f9301f80c5db3af03c6df @arantius arantius committed Dec 2, 2011
Showing with 21 additions and 14 deletions.
  1. +17 −12 content/script.js
  2. +4 −2 modules/remoteScript.js
View
29 content/script.js
@@ -486,7 +486,7 @@ Script.prototype.updateFromNewScript = function(newScript, safeWin, chromeWin) {
var rs = new scope.RemoteScript(this._downloadURL);
rs.setScript(newScript);
rs.download(GM_util.hitch(this, function(aSuccess) {
- rs.install(this);
+ rs.install(this, true);
}));
}
};
@@ -558,7 +558,6 @@ Script.prototype.checkRemoteVersion = function(req, aCallback) {
var versionChecker = Components
.classes["@mozilla.org/xpcom/version-comparator;1"]
.getService(Components.interfaces.nsIVersionComparator);
-
if (versionChecker.compare(this._version, remoteVersion) >= 0) {
return aCallback(false);
}
@@ -613,18 +612,24 @@ Script.prototype.installUpdate = function(aChromeWin, aCallback) {
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.
+ // new script details (version, primarily).
GM_util.timeout(
- 0, GM_util.hitch(GM_util.getService().config, '_changed',
- aNewScript, 'modified', oldScriptId));
+ 0, function() {
+ aCallback();
+ GM_util.getService().config._changed(
+ aNewScript, 'modified', oldScriptId);
+ });
}
- var uri = GM_util.uriFromUrl(this._downloadURL);
- var scriptDownloader = new GM_ScriptDownloader(aChromeWin, uri, null);
- scriptDownloader.replacedScript = this;
- scriptDownloader._installOnCompletion = true;
- scriptDownloader.onInstall(GM_util.hitch(this, updateAddons));
- if (aCallback) scriptDownloader.onInstall(aCallback);
- scriptDownloader.startDownload();
+
+ var scope = {};
+ Components.utils.import('resource://greasemonkey/remoteScript.js', scope);
+ var rs = new scope.RemoteScript(this._downloadURL);
+ rs.download(GM_util.hitch(this, function(aSuccess, aType) {
+ if (aSuccess && 'dependencies' == aType) {
+ rs.install(this);
+ updateAddons(rs.script);
+ }
+ }));
};
Script.prototype.allFiles = function() {
View
6 modules/remoteScript.js
@@ -211,12 +211,13 @@ RemoteScript.prototype.downloadScript = function(aCompletionCallback) {
GM_util.hitch(this, this._downloadScriptCb, aCompletionCallback));
};
-RemoteScript.prototype.install = function(aOldScript) {
+RemoteScript.prototype.install = function(aOldScript, aOnlyDependencies) {
if (!this.script) {
throw new Error('RemoteScript.install(): Script is not downloaded.');
}
+ if ('undefined' == typeof aOnlyDependencies) aOnlyDependencies = false;
- if (aOldScript) {
+ if (aOnlyDependencies) {
// Just move the dependencies in.
var enumerator = this._tempDir.directoryEntries;
while (enumerator.hasMoreElements()) {
@@ -267,6 +268,7 @@ RemoteScript.prototype.onScriptMeta = function(aCallback) {
*/
RemoteScript.prototype.setScript = function(aScript) {
this._scriptFile = aScript.file;
+ this._baseName = aScript._basedir;
this.script = aScript;
this._postParseScriptFile();
}

0 comments on commit 5ded763

Please sign in to comment.
Something went wrong with that request. Please try again.