You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/05/23 22:03:41 UTC
[18/30] git commit: Bugfixes. Extension extraction,
Uri encoding during app download. Unzip.
Bugfixes. Extension extraction, Uri encoding during app download. Unzip.
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/830dc5d9
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/830dc5d9
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/830dc5d9
Branch: refs/heads/master
Commit: 830dc5d9d1883f9c1e712ef259c434d288bd9fde
Parents: 94edf0c
Author: Shravan Narayan <sh...@google.com>
Authored: Sun May 12 01:11:04 2013 -0400
Committer: Shravan Narayan <sh...@google.com>
Committed: Mon May 13 18:07:18 2013 -0400
----------------------------------------------------------------------
www/cdvah_js/AddCtrl.js | 14 ++++-----
www/cdvah_js/AppsService.js | 10 +++---
www/cdvah_js/ContextMenu.js | 39 ++++++++++++++++-----------
www/cdvah_js/ResourcesLoader.js | 49 ++++++++++++++++++---------------
4 files changed, 61 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/830dc5d9/www/cdvah_js/AddCtrl.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/AddCtrl.js b/www/cdvah_js/AddCtrl.js
index b536d87..8827b1d 100644
--- a/www/cdvah_js/AddCtrl.js
+++ b/www/cdvah_js/AddCtrl.js
@@ -26,14 +26,12 @@
serviceCall = AppsService.addAppFromServe($scope.appData.appName, $scope.appData.appSourceServe);
}
- if(serviceCall) {
- serviceCall.then(function() {
- alert("Successfully installed");
- }, function(error) {
- console.error(error);
- alert("Unable to add application because: \n" + error);
- });
- }
+ serviceCall && serviceCall.then(function() {
+ alert("Successfully installed");
+ }, function(error) {
+ console.error(error);
+ alert("Unable to add application because: \n" + error);
+ });
};
}]);
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/830dc5d9/www/cdvah_js/AppsService.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/AppsService.js b/www/cdvah_js/AppsService.js
index f0d1b86..34358ce 100644
--- a/www/cdvah_js/AppsService.js
+++ b/www/cdvah_js/AppsService.js
@@ -20,7 +20,7 @@
}
function addNewAppFromPattern(appName, appSourcePattern) {
- var _fullFilePath;
+ var fullFilePath;
return ResourcesLoader.deleteDirectory(INSTALL_DIRECTORY + appName)
.then(function(){
@@ -31,16 +31,16 @@
}
throw new Error("App Harness does not know how to install an app from the pattern: " + appSourcePattern);
})
- .then(function(fullFilePath){
- _fullFilePath = fullFilePath;
+ .then(function(_fullFilePath){
+ fullFilePath = _fullFilePath;
return ResourcesLoader.ensureDirectoryExists(INSTALL_DIRECTORY + appName);
})
.then(function(directoryPath){
- var extension = grabExtensionFromUri(appSourcePattern);
+ var extension = grabExtensionFromUri(fullFilePath);
if(!extensionHandlers[extension]) {
throw new Error("No handler for extension " + extension + " found");
}
- return extensionHandlers[extension].extractPackageToDirectory(_fullFilePath, directoryPath);
+ return extensionHandlers[extension].extractPackageToDirectory(fullFilePath, directoryPath);
})
.then(function(){
return registerApp(appName, "pattern", appSourcePattern);
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/830dc5d9/www/cdvah_js/ContextMenu.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/ContextMenu.js b/www/cdvah_js/ContextMenu.js
index 452f656..bcfa1b6 100644
--- a/www/cdvah_js/ContextMenu.js
+++ b/www/cdvah_js/ContextMenu.js
@@ -23,22 +23,6 @@
}, false);
}
- function setupIframeMessaging(){
- window.addEventListener("message", function(e){
- if(e.data === "ContextMenuUpdate"){
- onContextMenuUpdateClicked();
- } else if(e.data === "ContextMenuRestart"){
- onContextMenuRestartClicked();
- } else if(e.data === "ContextMenuFirebug"){
- onContextMenuFirebugClicked();
- } else if(e.data === "ContextMenuMainMenu"){
- onContextMenuMainMenuClicked();
- }else if(e.data === "ContextMenuHide"){
- onContextMenuHideClicked();
- }
- } , false);
- }
-
function onContextMenuUpdateClicked(){
window.location = "app-bundle:///cdvah_index.html#/?updateLastLaunched=true";
}
@@ -76,6 +60,29 @@
document.getElementById(contextMenuIframe).style.display = "none";
}
+ var messageHandler = {
+ "ContextMenuUpdate" : onContextMenuUpdateClicked,
+ "ContextMenuRestart" : onContextMenuRestartClicked,
+ "ContextMenuFirebug" : onContextMenuFirebugClicked,
+ "ContextMenuMainMenu" : onContextMenuMainMenuClicked,
+ "ContextMenuHide" : onContextMenuHideClicked,
+ "ContextMenuWeinre" : onContextMenuWeinreNameChanged
+ };
+ function setupIframeMessaging(){
+ window.addEventListener("message", function(e){
+ var messageParts = [ e.data ];
+ var location = e.data.indexOf(":");
+ if(location !== -1){
+ messageParts = [ e.data.substring(0, location),
+ e.data.substring(location + 1)
+ ];
+ }
+ if(messageHandler[messageParts[0]]){
+ messageHandler[messageParts[0]](messageParts[1]);
+ }
+ } , false);
+ }
+
function loadFirebug(startOpened){
var el = document.createElement("script");
el.setAttribute("id", "FirebugLite");
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/830dc5d9/www/cdvah_js/ResourcesLoader.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/ResourcesLoader.js b/www/cdvah_js/ResourcesLoader.js
index b1e55ee..1f84681 100644
--- a/www/cdvah_js/ResourcesLoader.js
+++ b/www/cdvah_js/ResourcesLoader.js
@@ -52,8 +52,7 @@
};
var fileTransfer = new $window.FileTransfer();
- var uri = encodeURI(url);
- fileTransfer.download(uri, fullFilePath, downloadSuccess, downloadFail);
+ fileTransfer.download(url, fullFilePath, downloadSuccess, downloadFail);
} catch(e) {
deferred.reject(new Error(e));
} finally {
@@ -179,6 +178,24 @@
return deferred.promise;
}
+ function ensureDirectoryExists(directory){
+ return Q.fcall(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];
+ });
+ }
+
function writeToFile(fileName, contents, append) {
return getFileEntry(fileName, true)
.then(function(fileEntry){
@@ -238,19 +255,7 @@
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];
+ return ensureDirectoryExists(directory);
});
},
@@ -405,10 +410,13 @@
},
extractZipFile : function(fileName, outputDirectory){
- var deferred = Q.defer();
+ return initialiseFileSystem()
+ .then(function(){
+ return ensureDirectoryExists(outputDirectory);
+ })
+ .then(function(){
+ 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));
@@ -419,11 +427,8 @@
/* global zip */
zip.unzip(fileName, outputDirectory, onZipDone);
- } catch(e) {
- deferred.reject(e);
- } finally {
return deferred.promise;
- }
+ });
},
xhrGet : xhrGet