Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5116AD330 for ; Thu, 23 May 2013 20:03:26 +0000 (UTC) Received: (qmail 81264 invoked by uid 500); 23 May 2013 20:03:25 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 81210 invoked by uid 500); 23 May 2013 20:03:25 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 80753 invoked by uid 99); 23 May 2013 20:03:24 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 May 2013 20:03:24 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 60DDF894E96; Thu, 23 May 2013 20:03:24 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agrieve@apache.org To: commits@cordova.apache.org Date: Thu, 23 May 2013 20:03:34 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [11/30] New filenames.Url aliases.(New AppBundle plugin needed).Desc cont below Android has a bug where the web view will not throw intercept events if you are navigating to a location that matches a filename in your bundle. Thus in order to support url http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/771f02b2/www/cdvah_js/libs/q.min.js ---------------------------------------------------------------------- diff --git a/www/cdvah_js/libs/q.min.js b/www/cdvah_js/libs/q.min.js new file mode 100644 index 0000000..7a27b9a --- /dev/null +++ b/www/cdvah_js/libs/q.min.js @@ -0,0 +1,19 @@ +(function(k){"function"===typeof bootstrap?bootstrap("promise",k):"object"===typeof exports?module.exports=k():"function"===typeof define&&define.amd?define(k):"undefined"!==typeof ses?ses.ok()&&(ses.makeQ=k):Q=k()})(function(){function k(a){var b=Function.call;return function(){return b.apply(a,arguments)}}function L(a,b){b.stack&&("object"===typeof a&&null!==a&&a.stack&&-1===a.stack.indexOf(M))&&(a.stack=N(a.stack)+"\n"+M+"\n"+N(b.stack))}function N(a){for(var a=a.split("\n"),b=[],d=0;d=aa&&g<=ba}else c=!1;!c&&!(-1!==j.indexOf("(module.js:")||-1!==j.indexOf("(node.js:"))&&b.push(j)}return b.join("\n")}function P(){if(Error.captureStackTrace){var a,b,d=Error.prepareStackTrace;Error.prepareStackTrace=function(d,c){a=c[1].getFileName();b=c[1].getLineNumber()};Error().stack;Error.prepareStackTrace=d;O=a;return b}}function c(a){return p(a)}function i(){function a(a){b&&(j=p(a),t(b,function(a,b){l(function(){j.promiseDispatch.apply(j, +b)})},void 0),d=b=void 0)}var b=[],d=[],j,e=C(i.prototype),g=C(m.prototype);g.promiseDispatch=function(a,c,g){var e=h(arguments);b?(b.push(e),"when"===c&&g[1]&&d.push(g[1])):l(function(){j.promiseDispatch.apply(j,e)})};g.valueOf=function(){if(b)return g;var a=o(j);u(a)&&(j=a);return a};Error.captureStackTrace&&0=x){J=0;x*=4;for(var a=y&&Math.min(y-1,x);s=c)throw new TypeError;}while(1)}for(;d +
+ + Required + Invalid characters used + Too long +
+ + +
+ + Required +
+ +
+ Back To Main Menu + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/771f02b2/www/cdvah_views/list.html ---------------------------------------------------------------------- diff --git a/www/cdvah_views/list.html b/www/cdvah_views/list.html new file mode 100644 index 0000000..b73f196 --- /dev/null +++ b/www/cdvah_views/list.html @@ -0,0 +1,12 @@ +
    +
  • +

    {{app.Name}}

    +

    Installed on: {{app.Installed}}

    + + + +
  • +
+ +
+Add new App \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/771f02b2/www/contextMenu.html ---------------------------------------------------------------------- diff --git a/www/contextMenu.html b/www/contextMenu.html deleted file mode 100644 index c1e04fc..0000000 --- a/www/contextMenu.html +++ /dev/null @@ -1,53 +0,0 @@ - - -
-

Tap Anywhere to Close

- -
\ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/771f02b2/www/index.html ---------------------------------------------------------------------- diff --git a/www/index.html b/www/index.html deleted file mode 100644 index f48fc97..0000000 --- a/www/index.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - Cordova App Harness - - - - - - - - - - - - - - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/771f02b2/www/js/AddCtrl.js ---------------------------------------------------------------------- diff --git a/www/js/AddCtrl.js b/www/js/AddCtrl.js deleted file mode 100644 index 09a1c50..0000000 --- a/www/js/AddCtrl.js +++ /dev/null @@ -1,24 +0,0 @@ -(function(){ - "use strict"; - /* global myApp */ - myApp.controller("AddCtrl", ["$scope", "AppsService", function ($scope, AppsService) { - - $scope.addApp = function(appName, appSource, appSourcePattern) { - if(appSource === "pattern") { - if(!appSourcePattern) { - alert("Url not specified"); - return; - } - - AppsService.addAppFromPattern(appName, appSourcePattern) - .then(function() { - alert("Successfully installed"); - }, function(error) { - console.error(error); - alert("Unable to add application because: \n" + JSON.stringify(error)); - }); - } - }; - }]); - -})(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/771f02b2/www/js/AppConstants.js ---------------------------------------------------------------------- diff --git a/www/js/AppConstants.js b/www/js/AppConstants.js deleted file mode 100644 index 81f8b4d..0000000 --- a/www/js/AppConstants.js +++ /dev/null @@ -1,12 +0,0 @@ -(function() { - var TEMP_DIRECTORY = "cordova_app_harness_tempDir/"; - var INSTALL_DIRECTORY = "cordova_app_harness_installed_apps/"; - var APPS_JSON = "cordova_app_harness_installed_apps/apps.json"; - var METADATA_JSON = "cordova_app_harness_installed_apps/metadata.json"; - - /* global myApp */ - myApp.value("TEMP_DIRECTORY", TEMP_DIRECTORY); - myApp.value("INSTALL_DIRECTORY", INSTALL_DIRECTORY); - myApp.value("APPS_JSON", APPS_JSON); - myApp.value("METADATA_JSON", METADATA_JSON); -})(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/771f02b2/www/js/AppsService.js ---------------------------------------------------------------------- diff --git a/www/js/AppsService.js b/www/js/AppsService.js deleted file mode 100644 index 8868c07..0000000 --- a/www/js/AppsService.js +++ /dev/null @@ -1,253 +0,0 @@ -(function() { - "use strict"; - /* global myApp */ - myApp.factory("AppsService", [ "ResourcesLoader", "INSTALL_DIRECTORY", "TEMP_DIRECTORY", "APPS_JSON", "METADATA_JSON", function(ResourcesLoader, INSTALL_DIRECTORY, TEMP_DIRECTORY, APPS_JSON, METADATA_JSON) { - - var platformId = cordova.require("cordova/platform").id; - // downloaders that know how to download from certain patterns. - // Eg: The KnownExtensionDownloader MAY know how to download from any uri's that end in known extensions - var downloadHandlers = []; - // handlers that have registered to unpack certain extensions during the installation of an app - var extensionHandlers = {}; - - function grabExtensionFromUri(uri) { - var lastSegment = uri.split("#")[0].split("?")[0].split("/").pop(); - var dotLocation = lastSegment.lastIndexOf("."); - var extension = (dotLocation !== -1)? lastSegment.substring(dotLocation + 1) : ""; - return extension; - } - - function addNewAppFromPattern(appName, appSourcePattern) { - var _fullFilePath; - - return ResourcesLoader.deleteDirectory(INSTALL_DIRECTORY + appName) - .then(function(){ - for(var i = 0; i < downloadHandlers.length; i++){ - if(downloadHandlers[i].handler.canHandleSourcePattern(appSourcePattern)){ - return downloadHandlers[i].handler.downloadFromPattern(appName, appSourcePattern, TEMP_DIRECTORY); - } - } - throw new Error("App Harness does not know how to install an app from the pattern: " + appSourcePattern); - }) - .then(function(fullFilePath){ - _fullFilePath = fullFilePath; - return ResourcesLoader.ensureDirectoryExists(INSTALL_DIRECTORY + appName); - }) - .then(function(directoryPath){ - var extension = grabExtensionFromUri(appSourcePattern); - if(!extensionHandlers[extension]) { - throw new Error("No handler for extension " + extension + " found"); - } - return extensionHandlers[extension].extractPackageToDirectory(_fullFilePath, directoryPath); - }) - .then(function(){ - return registerApp(appName, "pattern", appSourcePattern); - }); - } - - function registerApp(appName, appSource, appSourcePattern) { - return ResourcesLoader.readJSONFileContents(APPS_JSON) - .then(function(result){ - result.installedApps = result.installedApps || []; - result.installedApps.push({ - "Name" : appName, - "Source" : appSource, - "Data" : appSourcePattern - "Installed" : (new Date()).toLocaleString() - }); - return ResourcesLoader.writeJSONFileContents(APPS_JSON, result); - }); - } - - function cleanPath(path){ - if(path.indexOf("file://") === 0){ - path = path.substring("file://".length); - } - // remove trailing slash - return (path.substring(path.length - 1) === "/") ? path.substring(0, path.length - 1) : path; - } - - function getAppStartPageFromConfig(configFile, appBaseDirectory) { - configFile = cleanPath(configFile); - appBaseDirectory = cleanPath(appBaseDirectory); - - return ResourcesLoader.readFileContents(configFile) - .then(function(contents){ - if(!contents) { - throw new Error("Config file is empty. Unable to find a start page for your app."); - } else { - var startLocation = appBaseDirectory + "/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) { - // Relative url's only currently - startLocation = appBaseDirectory + "/" + srcValue; - break; - } - } - } - - return startLocation; - } - }); - } - - function removeApp(appName){ - var entry; - return ResourcesLoader.ensureDirectoryExists(APPS_JSON) - .then(function() { - return ResourcesLoader.readJSONFileContents(APPS_JSON); - }) - .then(function(result){ - result.installedApps = result.installedApps || []; - - for(var i = 0; i < result.installedApps.length; i++){ - if(result.installedApps[i].Name === appName) { - entry = result.installedApps.splice(i, 1)[0]; - break; - } - } - - if(!entry) { - throw new Error("The app " + appName + " was not found."); - } - - return ResourcesLoader.writeJSONFileContents(APPS_JSON, result); - }) - .then(function(){ - return ResourcesLoader.deleteDirectory(INSTALL_DIRECTORY + appName); - }) - .then(function(){ - return entry; - }); - } - - return { - //return promise with the array of apps - getAppsList : function(getFullEntries) { - return ResourcesLoader.ensureDirectoryExists(APPS_JSON) - .then(function() { - return ResourcesLoader.readJSONFileContents(APPS_JSON); - }) - .then(function(result){ - result.installedApps = result.installedApps || []; - var newAppsList = []; - - for(var i = 0; i < result.installedApps.length; i++){ - if(getFullEntries) { - newAppsList.push(result.installedApps[i]); - } else { - newAppsList.push(result.installedApps[i].Name); - } - } - - return newAppsList; - }); - }, - - launchApp : function(appName) { - return ResourcesLoader.readJSONFileContents(METADATA_JSON) - .then(function(settings){ - settings = settings || {}; - settings.lastLaunched = appName; - return ResourcesLoader.writeJSONFileContents(METADATA_JSON, settings); - }) - .then(function(){ - return ResourcesLoader.getFullFilePath(INSTALL_DIRECTORY + appName); - }) - .then(function(appLocation) { - var appPlatformLocation = cleanPath(appLocation) + "/" + platformId; - return getAppStartPageFromConfig(appPlatformLocation + "/config.xml", appPlatformLocation + "/www/"); - }) - .then(function(startLocation) { - //ensure we use a file uri - if(startLocation.search("file://") !== 0){ - startLocation = "file://" + startLocation; - } - window.location = startLocation; - }); - }, - - addAppFromPattern : function(appName, appSourcePattern) { - return this.getAppsList(false /* App names only */) - .then(function(appsList){ - if(appsList.indexOf(appName) !== -1) { - throw new Error("An app with this name already exists"); - } - return addNewAppFromPattern(appName, appSourcePattern); - }); - }, - - uninstallApp : function(appName) { - return removeApp(appName); - }, - - getLastRunApp : function() { - return ResourcesLoader.readJSONFileContents(METADATA_JSON) - .then(function(settings){ - if(!settings || !settings.lastLaunched) { - throw new Error("No App has been launched yet"); - } - return settings.lastLaunched; - }); - }, - - registerPatternDownloader : function(handler, priority){ - if(!handler) { - throw new Error("Expected handler"); - } - if(typeof(handler.canHandleSourcePattern) !== "function") { - throw new Error("Expected function for bool handler.canHandleSourcePattern(string pattern) to exist"); - } - if(typeof(handler.downloadFromPattern) !== "function") { - throw new Error("Expected function for (string fullFilePath or QPromise) handler.downloadFromPattern(string appName, string pattern, string tempDirectory) to exist"); - } - if(!priority) { - // Assign a default priority - priority = 500; - } - var i = 0; - var objToInsert = { "priority" : priority, "handler" : handler }; - for(i = 0; i < downloadHandlers.length; i++){ - if(downloadHandlers[i].priority > objToInsert.priority) { - break; - } - } - downloadHandlers.splice(i, 0, objToInsert); - }, - - registerPackageHandler : function(extension, handler) { - if(!extension) { - throw new Error("Expcted extension"); - } - if(!handler || typeof(handler.extractPackageToDirectory) !== "function") { - throw new Error("Expected function for void handler.extractPackageToDirectory(string fullFilePath, string directoryPath) to exist"); - } - if(handler[extension]) { - throw new Error("Handler already exists for the extension: " + extension); - } - extensionHandlers[extension] = handler; - }, - - updateApp : function(appName){ - return removeApp(appName) - .then(function(entry){ - if(entry.Source === "pattern") { - return addNewAppFromPattern(entry.Name, entry.Data); - } - }); - }, - - getKnownExtensions : function() { - return Object.keys(extensionHandlers); - } - }; - }]); -})(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/771f02b2/www/js/CdvhPackageHandler.js ---------------------------------------------------------------------- diff --git a/www/js/CdvhPackageHandler.js b/www/js/CdvhPackageHandler.js deleted file mode 100644 index 212cd4b..0000000 --- a/www/js/CdvhPackageHandler.js +++ /dev/null @@ -1,60 +0,0 @@ -(function(){ - "use strict"; - /* global myApp */ - myApp.run(["AppsService", "ResourcesLoader", function(AppsService, ResourcesLoader){ - - var platformId = cordova.require("cordova/platform").id; - - function copyFile(startUrl, targetLocation){ - /************ Begin Work around for File system bug ************/ - if(targetLocation.indexOf("file://") === 0) { - targetLocation = targetLocation.substring("file://".length); - } - /************ End Work around for File system bug **************/ - return ResourcesLoader.xhrGet(startUrl) - .then(function(xhr){ - return ResourcesLoader.ensureDirectoryExists(targetLocation) - .then(function(){ - return ResourcesLoader.writeFileContents(targetLocation, xhr.responseText); - }); - }); - } - - var appendScript = function() { - console.log("Injecting menu script"); - var contextScript = document.createElement("script"); - contextScript.setAttribute("type","text/javascript"); - contextScript.setAttribute("src", "app-bundle:///js/ContextMenu.js"); - document.getElementsByTagName("head")[0].appendChild(contextScript); - }; - - AppsService.registerPackageHandler("cdvh", { - extractPackageToDirectory : function (fileName, outputDirectory){ - var dataToAppend = "\n(" + appendScript.toString() + ")();"; - var platformDirectory = outputDirectory + "/" + platformId + "/www/"; - var cordovaFile = platformDirectory + "cordova.js"; - var pluginsFile = platformDirectory + "cordova_plugins.json"; - - // We need to - // 1) Modify the cordova.js file - // 2) Copy the cordova_plugins.json we have, as the app that is being installed may have other plugins included which aren't in the harness. - // If we allow unavailable plugins to be included in this file, the plugin initialiser breaks - return ResourcesLoader.extractZipFile(fileName, outputDirectory) - .then(function(){ - return ResourcesLoader.doesFileExist(cordovaFile); - }) - .then(function(fileExists){ - if(fileExists){ - return Q.all([ - ResourcesLoader.appendFileContents(cordovaFile, dataToAppend), - copyFile("app-bundle:///cdvh_files/www/cordova_plugins.json", pluginsFile) - ]); - } else { - throw new Error("The package does not seem to have the files required for the platform: " + platformId); - } - }); - } - }); - - }]); -})(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/771f02b2/www/js/ContextMenu.js ---------------------------------------------------------------------- diff --git a/www/js/ContextMenu.js b/www/js/ContextMenu.js deleted file mode 100644 index 239a76c..0000000 --- a/www/js/ContextMenu.js +++ /dev/null @@ -1,84 +0,0 @@ -(function () { - - function initialise() { - var contextHTMLUrl = "app-bundle:///contextMenu.html"; - var xhr = new window.XMLHttpRequest(); - xhr.onreadystatechange=function() - { - if (xhr.readyState==4 && xhr.status==200) - { - var stringifiedHtml = xhr.responseText; - onInject(stringifiedHtml); - } - }; - // retrieve the context menu - xhr.open("GET", contextHTMLUrl, true); - xhr.send(); - - loadFirebug(false); - attachErrorListener(); - } - - function onInject(stringifiedHtml) { - - document.body.innerHTML += stringifiedHtml; - - var contextDiv = "__cordovaappharness_contextMenu_div"; - var showFirebugButton = "__cordovaappharness_contextMenu_firebug_button"; - - // Setup the listeners to toggle the context menu - document.addEventListener("touchmove", function (event) { - if(event.touches.length >= 3) { - document.getElementById(contextDiv).style.display = "inline"; - } - }, false); - - document.getElementById(contextDiv).onclick = function() { - document.getElementById(contextDiv).style.display = "none"; - }; - - var firstTime = true; - document.getElementById(showFirebugButton).onclick = function(){ - try { - if(firstTime){ - console.warn("Note that messages logged to the console at the app startup may not be visible here."); - console.warn("Do not use the close button on Firebug. Your console logs will be cleared. Use minimize instead."); - firstTime = false; - } - window.Firebug.chrome.open(); - } catch(e) { - // hack - FirebugLite appears to have several bugs. One of which is - open firebug, user shuts down FirebugLite through the UI. - // FirebugLite is now in a bad state of neither being usable or removable. Any calls to open throw an error. - // The following lines removes the flags that FirebugLite looks for manually and makes it think it has not loaded it yet - // Then FirebugLite is loaded into the page again - // This hack should be revisited when FirebugLite moves from version 1.4 - // Either the hack won't be needed anymore or the hack should be checked too see if it still works. - var el = document.getElementById("FirebugLite"); - if(el) { - el.setAttribute("id", ""); - } - delete console.firebuglite; - loadFirebug(true); - } - }; - } - - function loadFirebug(startOpened){ - var el = document.createElement("script"); - el.setAttribute("id", "FirebugLite"); - el.setAttribute("src", "https://getfirebug.com/firebug-lite.js"); - el.setAttribute("FirebugLite", "4"); - el.innerHTML = el.innerHTML = "{ debug : false, startOpened : " + startOpened + ", showIconWhenHidden : false, saveCommandLineHistory : true, saveCookies : false }"; - document.head.appendChild(el); - } - - // FirebugLite doesn't catch errors from window.onerror like desktop browser's dev tools do. So we add it manually. - function attachErrorListener(){ - window.onerror = function(msg, url, line) { - console.error("Error: " + msg + " on line: " + line + " in file: " + url); - }; - } - - initialise(); -})(); - http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/771f02b2/www/js/KnownExtensionDownloader.js ---------------------------------------------------------------------- diff --git a/www/js/KnownExtensionDownloader.js b/www/js/KnownExtensionDownloader.js deleted file mode 100644 index cec413a..0000000 --- a/www/js/KnownExtensionDownloader.js +++ /dev/null @@ -1,43 +0,0 @@ -(function(){ - "use strict"; - /* global myApp */ - myApp.run(["AppsService", "ResourcesLoader", function(AppsService, ResourcesLoader){ - - function isUri(pattern){ - var regexUri = /^(?:([a-z0-9+.-]+:\/\/)((?:(?:[a-z0-9-._~!$&'()*+,;=:]|%[0-9A-F]{2})*)@)?((?:[a-z0-9-._~!$&'()*+,;=]|%[0-9A-F]{2})*)(:(?:\d*))?(\/(?:[a-z0-9-._~!$&'()*+,;=:@\/]|%[0-9A-F]{2})*)?|([a-z0-9+.-]+:)(\/?(?:[a-z0-9-._~!$&'()*+,;=:@]|%[0-9A-F]{2})+(?:[a-z0-9-._~!$&'()*+,;=:@\/]|%[0-9A-F]{2})*)?)(\?(?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9A-F]{2})*)?(#(?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9A-F]{2})*)?$/i; - var ret = (pattern.search(regexUri) !== -1); - return ret; - } - - function grabExtensionFromUri(uri) { - var lastSegment = uri.split("#")[0].split("?")[0].split("/").pop(); - var dotLocation = lastSegment.lastIndexOf("."); - var extension = (dotLocation !== -1)? lastSegment.substring(dotLocation + 1) : ""; - return extension; - } - - // Note the priority given has no meaning in and of itself. It is used solely to compare if any other component has higher priority. - AppsService.registerPatternDownloader({ - canHandleSourcePattern : function (pattern) { - var canHandle = false; - if(isUri(pattern)) { - var currentExtension = grabExtensionFromUri(pattern); - if(currentExtension) { - var knownExtensions = AppsService.getKnownExtensions(); - if(knownExtensions.indexOf(currentExtension) !== -1){ - canHandle = true; - } - } - } - return canHandle; - }, - - downloadFromPattern : function (appName, pattern, tempDirectory) { - var extension = grabExtensionFromUri(pattern); - var fileName = tempDirectory + appName + "." + extension; - return ResourcesLoader.downloadFromUrl(pattern, fileName); - } - }, 500 /* assign a priority */); - - }]); -})(); http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/771f02b2/www/js/ListCtrl.js ---------------------------------------------------------------------- diff --git a/www/js/ListCtrl.js b/www/js/ListCtrl.js deleted file mode 100644 index d906f7c..0000000 --- a/www/js/ListCtrl.js +++ /dev/null @@ -1,94 +0,0 @@ -(function(){ - "use strict"; - /* global myApp */ - myApp.controller("ListCtrl", [ "$scope", "$routeParams", "AppsService", function ($scope, $routeParams, AppsService) { - - $scope.appsList = []; - - function initialise() { - if($routeParams.lastLaunched) { - return AppsService.getLastRunApp() - .then(AppsService.launchApp, function(e){ - e = e || {}; - console.error("Error launching last run app: " + e.message); - alert("Error launching last run app. Please try again."); - }); - } - else if($routeParams.updateLastLaunched) { - var app; - // updating may take a while so we show the apps list like we normally do - return $scope.loadAppsList(true) - .then(AppsService.getLastRunApp) - .then(function(_app){ - app = _app; - return AppsService.updateApp(app); - }) - .then(function(){ - return AppsService.launchApp(app); - }, function(e){ - e = e || {}; - console.error("Error updating last run app: " + e.message); - alert("Error updating last run app. Please try again."); - }); - } - else { - return $scope.loadAppsList(true); - } - } - - $scope.loadAppsList = function(callApply) { - return AppsService.getAppsList(true /* get full information about the app */) - .then(function(newAppsList){ - newAppsList.sort(function(a, b){ - if(a.Name < b.Name) { - return -1; - } else if(a.Name > b.Name) { - return 1; - } - return 0; - }); - //clear the old apps list - $scope.appsList.splice(0, $scope.appsList.length); - angular.extend($scope.appsList, newAppsList); - if(callApply) { - $scope.$apply(); - } - }, function(error){ - var str = "There was an error retrieving the apps list"; - console.error(str + JSON.stringify(error)); - alert(str); - }); - }; - - $scope.launchApp = function(app){ - return AppsService.launchApp(app) - .then(null, function(error){ - console.error("Error during loading of app " + app + ": " + error); - alert("Something went wrong during the loading of the app. Please try again."); - }); - }; - - $scope.updateApp = function(app) { - return AppsService.updateApp(app) - .then(function(){ - alert("Updated successfully"); - }, function(error){ - console.error("Error during updating of app " + app + ": " + error); - alert("Something went wrong during the updating of the app. Please try again."); - }); - }; - - $scope.removeApp = function(app) { - var shouldUninstall = confirm("Are you sure you want to uninstall " + app + "?"); - if(shouldUninstall) { - return AppsService.uninstallApp(app) - .then(function() { $scope.loadAppsList(true); }, function(error){ - console.error("Error during uninstall of app " + app + ": " + error); - alert("Something went wrong during the uninstall of the app. Please try again."); - }); - } - }; - - document.addEventListener("deviceready", initialise, false); - }]); -})(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/771f02b2/www/js/ResourcesLoader.js ---------------------------------------------------------------------- diff --git a/www/js/ResourcesLoader.js b/www/js/ResourcesLoader.js deleted file mode 100644 index 8aa52a9..0000000 --- a/www/js/ResourcesLoader.js +++ /dev/null @@ -1,404 +0,0 @@ -(function() { - "use strict"; - - /* global myApp */ - myApp.factory("ResourcesLoader", [ "$window", function ($window) { - var fs; - var initialised = false; - - function initialiseFileSystem() { - var deferred = Q.defer(); - - if(!initialised) { - - var failedFileSystemLookUp = function (error) { - var errorString = "An error occurred while reading the file system."; - if(error) { - errorString += " " + JSON.stringify(error); - } - deferred.reject(new Error(errorString)); - }; - - var success = function(_fs) { - fs = _fs; - initialised = true; - deferred.resolve(fs); - }; - - try { - $window.requestFileSystem($window.LocalFileSystem.PERSISTENT, 0, success, failedFileSystemLookUp); - } catch (e) { - failedFileSystemLookUp(e); - } - } else { - deferred.resolve(fs); - } - - return deferred.promise; - } - - //promise returns full path to downloaded file - function downloadFromUrl(url, fullFilePath) { - var deferred = Q.defer(); - - try { - var downloadFail = function(error) { - var str = "There was an error while downloading the file " + JSON.stringify(error); - deferred.reject(new Error(str)); - }; - - var downloadSuccess = function(fileEntry) { - deferred.resolve(fileEntry.fullPath); - }; - - var fileTransfer = new $window.FileTransfer(); - var uri = encodeURI(url); - fileTransfer.download(uri, fullFilePath, downloadSuccess, downloadFail); - } catch(e) { - deferred.reject(new Error(e)); - } finally { - return deferred.promise; - } - } - - function trim(str) { - return str && str.replace(/^\s+|\s+$/g, ""); - } - - function fixFilePath(path) { - if(path && path.indexOf("file://") === 0) { - path = path.substring("file://".length); - } - return path; - } - - //promise returns the directory entry - function getDirectoryEntry(directoryName) { - var deferred = Q.defer(); - - try { - var errorWhileGettingDirectoryEntry = function(error) { - var str = "There was an error while getting the directory entry for directory " + directoryName + " " + JSON.stringify(error); - deferred.reject(new Error(str)); - }; - var success = function(directoryEntry) { - deferred.resolve(directoryEntry); - }; - fs.root.getDirectory(directoryName, {create: true, exclusive: false}, success, errorWhileGettingDirectoryEntry); - } catch(e) { - deferred.reject(new Error(e)); - } finally { - return deferred.promise; - } - } - - //promise returns the file entry - function getFileEntry(fileName, createFlag) { - var deferred = Q.defer(); - - try { - var errorWhileGettingFileEntry = function(error) { - var str = "There was an error while getting the file entry for file " + fileName + " " + JSON.stringify(error); - deferred.reject(new Error(str)); - }; - var success = function(fileEntry) { - deferred.resolve(fileEntry); - }; - // !! - ensures a boolean value - fs.root.getFile(fileName, {create: !!createFlag, exclusive: false}, success, errorWhileGettingFileEntry); - } catch(e) { - deferred.reject(new Error(e)); - } finally { - return deferred.promise; - } - } - - //promise returns the file - function getFile(fileName) { - return getFileEntry(fileName, true /* create */). - then(function(fileEntry){ - var deferred = Q.defer(); - - try { - var errorWhileGettingFile = function(error) { - var str = "There was an error while getting the file for file " + fileName + " " + JSON.stringify(error); - deferred.reject(new Error(str)); - }; - - fileEntry.file(deferred.resolve, errorWhileGettingFile); - } catch(e) { - deferred.reject(new Error(e)); - } finally { - return deferred.promise; - } - }); - } - - function truncateToDirectoryPath(path) { - //remove the filename if it exists - var lastLevelIndex = path.search(/[\w ]+(\.[\w ]+)+$/g); - if(lastLevelIndex !== -1) { - path = path.substring(0, lastLevelIndex); - } - return path; - } - - function getPathSegments(path){ - //truncate leading and trailing slashes - if(path.charAt(0) === "/"){ - path = path.substring(1); - } - if(path.charAt(path.length - 1) === "/"){ - path = path.substring(0, path.length - 1); - } - var segments = path.split("/"); - return segments; - } - - function ensureSingleDirectoryExists(directory){ - var deferred = Q.defer(); - - var gotDirEntry = function(dirEntry) { - deferred.resolve(dirEntry.fullPath); - }; - - var failedToGetDirEntry = function(error) { - var str = "There was an error checking the directory: " + directory + " " + JSON.stringify(error); - deferred.reject(new Error(str)); - }; - - fs.root.getDirectory(directory, {create: true, exclusive: false}, gotDirEntry, failedToGetDirEntry); - return deferred.promise; - } - - function writeToFile(fileName, contents, append) { - return getFileEntry(fileName, true) - .then(function(fileEntry){ - var deferred = Q.defer(); - - var errorGettingFileWriter = function(error) { - var str = "There was an error writing the file." + JSON.stringify(error); - deferred.reject(new Error(str)); - }; - - var gotFileWriter = function(writer) { - writer.onwrite = deferred.resolve; - writer.onerror = function(evt) { - deferred.reject(new Error(evt)); - }; - if(append){ - writer.seek(writer.length); - } - writer.write(contents); - }; - fileEntry.createWriter(gotFileWriter, errorGettingFileWriter); - return deferred.promise; - }); - } - - return { - doesFileExist : function(fileName){ - return initialiseFileSystem() - .then(function(){ - return getFileEntry(fileName, false /* create */); - }) - .then(function(){ - return true; - }, function(){ - return false; - }); - }, - - // returns a promise with a full path to the dir - ensureDirectoryExists : function(directory) { - return initialiseFileSystem() - .then(function(){ - directory = truncateToDirectoryPath(directory); - directory = fixFilePath(directory); - var segments = getPathSegments(directory); - var currentDir = directory.charAt(0) === "/"? "/" : ""; - var promiseArr = []; - while(segments.length !== 0) { - currentDir += segments.shift() + "/"; - promiseArr.push(ensureSingleDirectoryExists(currentDir)); - } - return Q.all(promiseArr); - }) - .then(function(paths){ - return paths[paths.length - 1]; - }); - }, - - // promise returns full path to file - getFullFilePath : function(filePath) { - return initialiseFileSystem() - .then(function(){ - var deferred = Q.defer(); - - // Use the file's parent folder to get the full path - var directory = filePath; - var fileName = ""; - - //remove the filename if it exists - var lastLevelIndex = directory.search(/\/[\w ]+\.[\w ]+$/g); - if(lastLevelIndex !== -1) { - directory = filePath.substring(0, lastLevelIndex); - fileName = filePath.substring(lastLevelIndex + 1); - } - - //we need the directory name w.r.t the root, so remove any slashes in the beginning - if(directory.charAt(0) === "/") { - directory = directory.substring(1); - } - - var gotFullPath = function(dirEntry) { - var fullFilePath = dirEntry.fullPath + "/" + fileName; - deferred.resolve(fullFilePath); - }; - - var failedToGetFullPath = function(error) { - var str = "There was an error getting the full path of file: " + filePath + " " + JSON.stringify(error); - deferred.reject(new Error(str)); - }; - - fs.root.getDirectory(directory, {create: true, exclusive: false}, gotFullPath, failedToGetFullPath); - return deferred.promise; - }); - }, - - // returns a promise with a full path to the downloaded file - downloadFromUrl : function(url, filePath) { - var self = this; - return initialiseFileSystem() - .then(function(){ - return self.ensureDirectoryExists(filePath); - }) - .then(function(){ - return self.getFullFilePath(filePath); - }) - .then(function(fullFilePath){ - return downloadFromUrl(url, fullFilePath); - }); - }, - - //returns a promise with the contents of the file - readFileContents : function(fileName) { - return initialiseFileSystem() - .then(function(){ - return getFile(fileName); - }) - .then(function(file){ - var deferred = Q.defer(); - - var reader = new $window.FileReader(); - reader.onload = function(evt) { - var text = evt.target.result; - deferred.resolve(text); - }; - reader.onerror = function(evt) { - deferred.reject(new Error(evt)); - }; - reader.readAsText(file); - - return deferred.promise; - }); - }, - - //returns a promise with the json contents of the file - readJSONFileContents : function(fileName) { - return this.readFileContents(fileName) - .then(function (text) { - text = trim(text); - var resultJson = {}; - if(text) { - resultJson = JSON.parse(text); - } - return resultJson; - }); - }, - - //returns a promise when file is written - writeFileContents : function(fileName, contents) { - return initialiseFileSystem() - .then(function(){ - return writeToFile(fileName, contents, false /* append */); - }); - }, - - //returns a promise when file is appended - appendFileContents : function(fileName, contents) { - return initialiseFileSystem() - .then(function(){ - return writeToFile(fileName, contents, true /* append */); - }); - }, - - //returns a promise when json file is written - writeJSONFileContents : function(fileName, contents) { - var stringContents; - if(typeof contents === "string") { - stringContents = contents; - } else { - stringContents = JSON.stringify(contents); - } - return this.writeFileContents(fileName, stringContents); - }, - - deleteDirectory : function(directoryName) { - return initialiseFileSystem() - .then(function(){ - return getDirectoryEntry(directoryName); - }) - .then(function(dirEntry){ - var deferred = Q.defer(); - var failedToDeleteDirectory = function(error) { - var str = "There was an error deleting the directory: " + directoryName + " " + JSON.stringify(error); - deferred.reject(new Error(str)); - }; - dirEntry.removeRecursively(deferred.resolve, failedToDeleteDirectory); - return deferred.promise; - }); - }, - - extractZipFile : function(fileName, outputDirectory){ - var deferred = Q.defer(); - - //will throw an exception if the zip plugin is not loaded - try { - var onZipDone = function(returnCode) { - if(returnCode !== 0) { - deferred.reject(new Error("Something went wrong during the unzipping of: " + fileName)); - } else { - deferred.resolve(); - } - }; - - /* global zip */ - zip.unzip(fileName, outputDirectory, onZipDone); - } catch(e) { - deferred.reject(e); - } finally { - return deferred.promise; - } - }, - - xhrGet : function(url) { - var deferred = Q.defer(); - var xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() { - if (xhr.readyState === 4) { - if(xhr.status === 200) { - deferred.resolve(xhr); - } else { - deferred.reject("XHR return status: " + xhr.statusText); - } - } - }; - xhr.open("GET", url, true); - xhr.send(); - return deferred.promise; - } - }; - }]); - -})(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/771f02b2/www/js/app.js ---------------------------------------------------------------------- diff --git a/www/js/app.js b/www/js/app.js deleted file mode 100644 index 962571e..0000000 --- a/www/js/app.js +++ /dev/null @@ -1,11 +0,0 @@ -var myApp = angular.module("CordovaAppHarness", []); -myApp.config(["$routeProvider", function($routeProvider){ - $routeProvider.when("/", { - templateUrl: "views/list.html", - controller: "ListCtrl" - }); - $routeProvider.when("/add", { - templateUrl: "views/add.html", - controller: "AddCtrl" - }); -}]); \ No newline at end of file