Support the start page from config.xml Added a script to package the www directory as well as the platform specific "config.xml"s Add code to go through the config.xml file to figure out the start page before launching an app
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/818a264a Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/818a264a Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/818a264a Branch: refs/heads/master Commit: 818a264a797a372a7e75ccc14ad9193e74e50004 Parents: 609e620 Author: Shravan Narayan <[email protected]> Authored: Tue Apr 23 19:33:06 2013 -0400 Committer: Shravan Narayan <[email protected]> Committed: Wed Apr 24 16:28:53 2013 -0400 ---------------------------------------------------------------------- .jshintrc | 2 +- README.md | 5 ++- checkjs | 22 ++++++++++++++ www/js/AppsService.js | 41 ++++++++++++++++++++++---- zipapp | 69 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 131 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/818a264a/.jshintrc ---------------------------------------------------------------------- diff --git a/.jshintrc b/.jshintrc index 0fef34f..82394b2 100644 --- a/.jshintrc +++ b/.jshintrc @@ -27,5 +27,5 @@ "devel":true, //other - "globals": {"angular": false, "Q": false } + "globals": {"angular": false, "Q": false, "cordova" : false } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/818a264a/README.md ---------------------------------------------------------------------- diff --git a/README.md b/README.md index 0bed757..05964e0 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,12 @@ An App harness for Cordova that can download and run Cordova apps as well as Chr ##Using the app +* Run the zipapp script and point it to a cordova project. This will package the app into a zip file. (Note: it is expected that you add all relavant platforms. For example, if you want to test on the iphone, you need to have added the ios platform to the project) + Repo/cordova-app-harness/zipapp ./TestApp TestApp.zip +* Upload the the zip onto any hosting site. * Run the app harness * Click add new app -* Give a name and a url to a zip. The zip should contain a www directory with a index.html file as the start page +* Give a name and the url to the zip. * Go back to the main screen after you see the prompt "successfully installed" * Click launch on the newly installed app * See if the app looks as expected http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/818a264a/checkjs ---------------------------------------------------------------------- diff --git a/checkjs b/checkjs index fc457d0..200d824 100755 --- a/checkjs +++ b/checkjs @@ -1,3 +1,25 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# run jshint with the required parameters +# +# USAGE +# ./checkjs +# echo "Running jsHint" jshint www/js/ --verbose --show-non-errors http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/818a264a/www/js/AppsService.js ---------------------------------------------------------------------- diff --git a/www/js/AppsService.js b/www/js/AppsService.js index f6dadd6..e6f7f15 100644 --- a/www/js/AppsService.js +++ b/www/js/AppsService.js @@ -3,6 +3,8 @@ /* global myApp */ myApp.factory("AppsService", [ "ResourcesLoader", "INSTALL_DIRECTORY", "TEMP_DIRECTORY", "APPS_JSON", function(ResourcesLoader, INSTALL_DIRECTORY, TEMP_DIRECTORY, APPS_JSON) { + var platformId = cordova.require("cordova/platform").id; + function addNewAppFromUrl(appName, appUrl) { var fileName = TEMP_DIRECTORY + appName + ".zip"; var _fullFilePath; @@ -56,8 +58,33 @@ function getAppStartPageFromAppLocation(appLocation) { appLocation += (appLocation.substring(appLocation.length - 1) === "/") ? "" : "/"; - var startLocation = appLocation + "www/index.html"; - return startLocation; + var configFile = appLocation + "config." + platformId + ".xml"; + + return ResourcesLoader.readFileContents(configFile) + .then(function(contents){ + if(!contents) { + throw new Error("config.xml for your platform is empty. Check if the zip package contains config.xml for your platform"); + } else { + var startLocation = appLocation + "www/index.html"; + var parser = new DOMParser(); + var xmlDoc = parser.parseFromString(contents, "text/xml"); + var els = xmlDoc.getElementsByTagName("content"); + + if(els.length > 0) { + // go through all "content" elements looking for the "src" attribute in reverse order + for(var i = els.length - 1; i >= 0; i--) { + var el = els[i]; + var srcValue = el.getAttribute("src"); + if(srcValue) { + startLocation = appLocation + "www/" + srcValue; + break; + } + } + } + + return startLocation; + } + }); } return { @@ -80,10 +107,12 @@ }, launchApp : function(appName) { - return ResourcesLoader.getFullFilePath(INSTALL_DIRECTORY + appName) - .then(function(appLocation) { - var startLocation = getAppStartPageFromAppLocation(appLocation); - document.location = startLocation; + return getAppStartPageFromAppLocation(INSTALL_DIRECTORY + appName + "/") + .then(function(startLocation) { + return ResourcesLoader.getFullFilePath(startLocation); + }) + .then(function(fullStartLocation){ + document.location = fullStartLocation; }); }, http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/818a264a/zipapp ---------------------------------------------------------------------- diff --git a/zipapp b/zipapp new file mode 100755 index 0000000..d4e8457 --- /dev/null +++ b/zipapp @@ -0,0 +1,69 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# package a cordova project into a zip for app harness +# +# USAGE +# ./zipapp project_directory [zipfileName] +# +if [ $# -lt 1 ] +then + echo "Usage: zipapp project_directory [zipfileName]" + exit -1 +fi + +ORIG_DIR=$(pwd) + + +cd $1 +FILE_NAME=$(basename "`pwd`" ).zip + +if [ $# -ge 2 ] +then + FILE_NAME=$2 +fi + +if [ -d "./platforms/android" ] +then + echo "Platform: android found" + cp -f ./platforms/android/res/xml/config.xml ./app/config.android.xml + if [ -f "./app/config.android.xml" ] + then + echo "Platform: android added successfully" + else + echo "Unable to locate config.xml for android" + fi +fi + +if [ -d "./platforms/ios" ] +then + echo "Platform: ios found" + find ./platforms/ios/ -name config.xml -exec cp {} ./app/config.ios.xml \; + if [ -f "./app/config.ios.xml" ] + then + echo "Platform: ios added successfully" + else + echo "Unable to locate config.xml for ios" + fi +fi + + +cd ./app +zip -r $ORIG_DIR/$FILE_NAME www config.*.xml + +rm config.*.xml \ No newline at end of file
