cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject git commit: Fix serve installer not waiting for update to complete
Date Wed, 07 May 2014 20:48:57 GMT
Repository: cordova-app-harness
Updated Branches:
  refs/heads/master c29e06c34 -> 55c4c8657


Fix serve installer not waiting for update to complete


Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/55c4c865
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/55c4c865
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/55c4c865

Branch: refs/heads/master
Commit: 55c4c86570f65f18d4b5266320d686326e459467
Parents: c29e06c
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Wed May 7 16:47:17 2014 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Wed May 7 16:48:10 2014 -0400

----------------------------------------------------------------------
 www/cdvah/js/ServeInstaller.js | 44 ++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/55c4c865/www/cdvah/js/ServeInstaller.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/ServeInstaller.js b/www/cdvah/js/ServeInstaller.js
index b9a893c..ae812cd 100644
--- a/www/cdvah/js/ServeInstaller.js
+++ b/www/cdvah/js/ServeInstaller.js
@@ -40,36 +40,33 @@
         };
 
         function fetchMetaServeData(url) {
-            var deferred = $q.defer();
-            var ret = {
-                url: url,
-                projectJson: null,
-                configXml: null,
-                appId: null
-            };
             var projectJsonUrl = url + '/' + platformId + '/project.json';
-            ResourcesLoader.xhrGet(projectJsonUrl, true)
-            .then(function(data) {
-                ret.projectJson = data;
-                return ResourcesLoader.xhrGet(url + ret.projectJson.configPath);
-            }, function(e) {
+            return ResourcesLoader.xhrGet(projectJsonUrl, true)
+            .then(null, function(e) {
                 // If there was no :8000, try again with one appended.
                 if (!/:(\d)/.test(url)) {
                     var newUrl = url.replace(/(.*?\/\/[^\/]*)/, '$1:8000');
                     if (newUrl != url) {
-                        return fetchMetaServeData(newUrl);
+                        url = newUrl;
+                        projectJsonUrl = url + '/' + platformId + '/project.json';
+                        return ResourcesLoader.xhrGet(projectJsonUrl, true);
                     }
                 }
-                deferred.reject(e);
-            })
-            .then(function(data) {
-                ret.configXml = data;
-                var configXml = new DOMParser().parseFromString(ret.configXml, 'text/xml');
-                ret.appId = configXml.firstChild.getAttribute('id');
-                return ret;
+                throw e;
             })
-            .then(deferred.resolve, deferred.reject);
-            return deferred.promise;
+            .then(function(projectJson) {
+                return ResourcesLoader.xhrGet(url + projectJson.configPath)
+                .then(function(configXmlRaw) {
+                    var configXml = new DOMParser().parseFromString(configXmlRaw, 'text/xml');
+                    var appId = configXml.firstChild.getAttribute('id');
+                    return {
+                        url: url,
+                        projectJson: projectJson,
+                        configXml: configXmlRaw,
+                        appId: appId
+                    };
+                });
+            });
         }
         // TODO: update should be more atomic. Maybe download to a new directory?
         ServeInstaller.prototype.doUpdateApp = function() {
@@ -122,9 +119,10 @@
                 }
                 console.log(destPath);
                 i += 1;
-                return ResourcesLoader.downloadFromUrl(sourceUrl, destPath).then(downloadNext);
+                ResourcesLoader.downloadFromUrl(sourceUrl, destPath).then(downloadNext, deferred.reject);
             }
             downloadNext();
+            return deferred.promise;
         };
 
         ServeInstaller.prototype._doUpdateAppForReal = function() {


Mime
View raw message