cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [11/17] git commit: Change config.xml-derived properties in installer into getters
Date Sat, 25 Oct 2014 01:26:29 GMT
Change config.xml-derived properties in installer into getters


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/c7bb0ef1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/c7bb0ef1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/c7bb0ef1

Branch: refs/heads/master
Commit: c7bb0ef1cdbb2ca63eb239458c60491beb4dead4
Parents: 9f5a427
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Fri Oct 3 12:56:08 2014 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Oct 24 21:26:07 2014 -0400

----------------------------------------------------------------------
 www/cdvah/js/Installer.js      | 102 +++++++++++++++++++++++++++---------
 www/cdvah/views/inappmenu.html |   2 +-
 www/cdvah/views/list.html      |   3 +-
 3 files changed, 80 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c7bb0ef1/www/cdvah/js/Installer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/Installer.js b/www/cdvah/js/Installer.js
index 44d5d07..fb00d07 100644
--- a/www/cdvah/js/Installer.js
+++ b/www/cdvah/js/Installer.js
@@ -28,13 +28,11 @@
         Installer.prototype.init = function(installPath, /* optional */ appId) {
             var ret = this;
             ret.appType = ret.constructor.type;
-            ret.updatingStatus = null;
+            ret.appId = appId || 'default'; // Stored in apps.json. May be different from
id within config.xml.
             ret.lastUpdated = null;
-            // Asset manifest is a cache of what files have been downloaded along with their
etags.
-            ret.appId = null; // Read from config.xml
-            ret.appName = null; // Read from config.xml
-            ret.iconURL = null; // Read from config.xml
-            ret.startPage = null; // Read from config.xml
+            // Derived values:
+            ret.updatingStatus = null;
+            ret.configXmlDom = null; // Read from config.xml
             ret.plugins = {}; // Read from orig-cordova_plugins.js
             ret.appId = appId;
             ret.directoryManager = new DirectoryManager();
@@ -50,7 +48,7 @@
             return this.init(json['installPath'], json['appId'])
             .then(function(ret) {
                 ret.lastUpdated = json['lastUpdated'] && new Date(json['lastUpdated']);
-                return self.readConfigXml();
+                return self.readConfigXml_();
             });
         };
 
@@ -63,27 +61,77 @@
             };
         };
 
-        Installer.prototype.readConfigXml = function() {
+        Installer.prototype.readConfigXml_ = function() {
             var self = this;
             return ResourcesLoader.readFileContents(this.directoryManager.rootURL + 'config.xml')
             .then(function(configStr) {
-                function lastEl(els) {
-                    return els[els.length - 1];
-                }
-                var xmlDoc = new DOMParser().parseFromString(configStr, 'text/xml');
-                self.appId = xmlDoc.firstChild.getAttribute('id');
-                var el = lastEl(xmlDoc.getElementsByTagName('content'));
-                self.startPage = el ? el.getAttribute('src') : 'index.html';
-                el = lastEl(xmlDoc.getElementsByTagName('icon'));
-                self.iconURL = el ? el.getAttribute('src') : null;
-                if (self.iconURL) {
-                    self.iconURL = self.directoryManager.rootURL + self.iconURL;
-                }
-                el = lastEl(xmlDoc.getElementsByTagName('name'));
-                self.appName = el ? el.textContent : null;
+                self.configXmlDom = new DOMParser().parseFromString(configStr, 'text/xml');
             });
         };
 
+        function lastEl(els) {
+            return els[els.length - 1];
+        }
+
+        Installer.prototype.getAppName = function() {
+            if (!this.configXmlDom) {
+                return '';
+            }
+            var el = lastEl(this.configXmlDom.getElementsByTagName('name'));
+            return el && el.textContent;
+        };
+
+        Installer.prototype.getIconUrl = function() {
+            if (!this.configXmlDom) {
+                return '';
+            }
+            var el = lastEl(this.configXmlDom.getElementsByTagName('icon'));
+            var ret = el && el.getAttribute('src');
+            // Don't set icon until the file exists.
+            if (!ret || !this.directoryManager.getAssetEtag(ret)) {
+                return '';
+            }
+            ret = this.directoryManager.rootURL + ret;
+            return ret;
+        };
+
+        Installer.prototype.getStartPage = function() {
+            var el = lastEl(this.configXmlDom.getElementsByTagName('content'));
+            var ret = el ? el.getAttribute('src') : 'index.html';
+            return ret;
+        };
+
+        Installer.prototype.getVersion = function() {
+            if (!this.configXmlDom) {
+                return '';
+            }
+            var widgetEl = this.configXmlDom.lastChild;
+            return widgetEl.getAttribute('version');
+        };
+
+        Installer.prototype.getConfigXmlId = function() {
+            if (!this.configXmlDom) {
+                return '';
+            }
+            var widgetEl = this.configXmlDom.lastChild;
+            return widgetEl.getAttribute('id');
+        };
+
+        Installer.prototype.getAndroidVersionCode = function() {
+            // copied from android_parser.js
+            function defaultVersionCode(version) {
+                var nums = version.split('-')[0].split('.').map(Number);
+                var versionCode = nums[0] * 10000 + nums[1] * 100 + nums[2];
+                return versionCode;
+            }
+
+            var versionCode = this.configXmlDom.lastChild.getAttribute('android-versionCode');
+            if (versionCode) {
+                return +versionCode;
+            }
+            return defaultVersionCode(this.getVersion() || '0.0.1');
+        };
+
         Installer.prototype.updateCordovaPluginsFile = function(etag) {
             var self = this;
             return $q.when(self.getPluginMetadata())
@@ -97,7 +145,7 @@
 
         Installer.prototype.onFileAdded = function(path) {
             if (path == 'config.xml') {
-                return this.readConfigXml();
+                return this.readConfigXml_();
             }
         };
 
@@ -118,14 +166,18 @@
             return $q.when();
         };
 
+        Installer.prototype.getWwwDir = function() {
+            return this.directoryManager.rootURL + 'www/';
+        };
+
         Installer.prototype.launch = function() {
             var self = this;
             return $q.when(this._prepareForLaunch())
             .then(function() {
                 var urlutil = cordova.require('cordova/urlutil');
                 var harnessWwwUrl = urlutil.makeAbsolute(location.pathname).replace(/\/[^\/]*\/[^\/]*$/,
'/');
-                var appWwwUrl = self.directoryManager.rootURL + 'www/';
-                var startLocation = urlutil.makeAbsolute(self.startPage).replace('/cdvah/',
'/');
+                var appWwwUrl = self.getWwwDir();
+                var startLocation = urlutil.makeAbsolute(self.getStartPage()).replace('/cdvah/',
'/');
                 var realStartLocation = startLocation.replace(harnessWwwUrl, appWwwUrl);
                 var useRemapper = platformId == 'android';
 

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c7bb0ef1/www/cdvah/views/inappmenu.html
----------------------------------------------------------------------
diff --git a/www/cdvah/views/inappmenu.html b/www/cdvah/views/inappmenu.html
index 2b0fd4c..c520b23 100644
--- a/www/cdvah/views/inappmenu.html
+++ b/www/cdvah/views/inappmenu.html
@@ -17,7 +17,7 @@
   under the License.
 -->
 <div class="in-app-menu-container">
-  <h1>{{app.appName || app.appId}}</h1>
+  <h1>{{app.getAppName() || app.getConfigXmlId() || app.appId}}</h1>
   <button ng-click="restartApp()">Restart App</button><br>
   <button ng-click="quitApp()">Quit App</button>
 </div>

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/c7bb0ef1/www/cdvah/views/list.html
----------------------------------------------------------------------
diff --git a/www/cdvah/views/list.html b/www/cdvah/views/list.html
index ac4c1df..7d74ad2 100644
--- a/www/cdvah/views/list.html
+++ b/www/cdvah/views/list.html
@@ -23,7 +23,7 @@
     <h3 class="topcoat-list__header">Installed Apps</h3>
     <ul class="topcoat-list">
         <li class="topcoat-list__item" ng-repeat="app in appList">
-            <div>{{app.appId}}</div>
+            <div>{{app.getAppName() || app.getConfigXmlId() || app.appId}}</div>
             <div ng-show="app.updatingStatus === null">Last updated: <span am-time-ago="app.lastUpdated"></span></div>
             <div ng-show="app.updatingStatus !== null">Update in progress: {{app.updatingStatus}}%</div>
             <div ng-show="app.plugins.missing.length + app.plugins.newer.length + app.plugins.older.length
> 0">
@@ -39,6 +39,7 @@
             <button ng-click="showDetails($index)">Details</button>
         </li>
     </ul>
+  </div>
 </div>
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message