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 2014/03/21 05:34:28 UTC
[4/5] git commit: Auto-listen when harness-push plugin exists
(instead of pushing a button)
Auto-listen when harness-push plugin exists (instead of pushing a button)
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/afdd006f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/afdd006f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/afdd006f
Branch: refs/heads/master
Commit: afdd006f37dec2e4fe480e51508bebde04578df6
Parents: feaebe8
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Mar 20 14:25:22 2014 -0700
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Mar 20 21:32:31 2014 -0700
----------------------------------------------------------------------
www/cdvah/js/ListCtrl.js | 127 ++++++++++++++++++++---------------------
www/cdvah/views/list.html | 5 +-
2 files changed, 64 insertions(+), 68 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/afdd006f/www/cdvah/js/ListCtrl.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/ListCtrl.js b/www/cdvah/js/ListCtrl.js
index f49912d..fe6cb46 100644
--- a/www/cdvah/js/ListCtrl.js
+++ b/www/cdvah/js/ListCtrl.js
@@ -4,7 +4,7 @@
/* global appharness */
myApp.controller('ListCtrl', ['$location', 'notifier', '$rootScope', '$scope', '$routeParams', '$q', 'AppsService', function ($location, notifier, $rootScope, $scope, $routeParams, $q, AppsService) {
$scope.appList = [];
- $rootScope.appTitle = 'Cordova App Harness';
+ $rootScope.appTitle = document.title;
function initialise() {
return $scope.loadAppsList()
@@ -31,6 +31,67 @@
});
}
}
+ }).then(function() {
+ if (!window.appharness || !appharness.push) {
+ return;
+ }
+
+ // listen is a no-op if already listening.
+ appharness.push.listen(function() {
+ $scope.listening = true;
+ $scope.$apply();
+ }, notifier.error);
+
+ appharness.push.getListenAddress(function(value) {
+ $scope.ipAddress = value;
+ $scope.$apply();
+ });
+
+ appharness.push.pending(function(obj) {
+ console.log('Return from pending: ' + obj);
+ if (obj && obj.type) {
+ AppsService.getAppList().then(function(list) {
+ console.log(list);
+ var matches = list && list.filter(function(x) { return x.appId == obj.name; });
+ var promise;
+ if (list && matches.length > 0) {
+ // App exists.
+ var app = matches[0];
+ app.url = obj.url;
+ promise = $q.when(app);
+ } else {
+ // New app.
+ var handler;
+ promise = AppsService.addApp(obj.type, obj.url).then(function(h) {
+ handler = h;
+ var msg = 'Added new app ' + handler.appId + ' from push';
+ console.log(msg);
+ notifier.success(msg);
+ }).then(function() {
+ // Reload so the app is visible while it's updating (below).
+ return $scope.loadAppsList().then(function() {
+ return handler;
+ });
+ });
+ }
+
+ var theApp;
+ promise.then(function(app) {
+ theApp = app;
+ return AppsService.updateApp(app);
+ }).then(function() {
+ notifier.success('Updated ' + theApp.appId + ' due to remote push.');
+ return $scope.loadAppsList();
+ }).then(function() {
+ return $scope.launchApp(theApp, { stopPropagation: function() { } });
+ }).done(null, function(err) {
+ var msg = 'Failed to update ' + app.appId + ': ' + err;
+ console.error(msg);
+ notifier.error(msg);
+ });
+ });
+ }
+ });
});
}
@@ -99,70 +160,6 @@
initialise();
- if (window.appharness && appharness.push) {
- appharness.push.listening(function(res) {
- $scope.listening = res;
- $scope.$apply();
- }, notifier.error);
-
- appharness.push.getListenAddress(function(value) {
- $scope.ipAddress = value;
- $scope.$apply();
- });
-
- appharness.push.pending(function(obj) {
- console.log('Return from pending: ' + obj);
- if (obj && obj.type) {
- AppsService.getAppList().then(function(list) {
- console.log(list);
- var matches = list && list.filter(function(x) { return x.appId == obj.name; });
- var promise;
- if (list && matches.length > 0) {
- // App exists.
- var app = matches[0];
- app.url = obj.url;
- promise = $q.when(app);
- } else {
- // New app.
- var handler;
- promise = AppsService.addApp(obj.type, obj.url).then(function(h) {
- handler = h;
- var msg = 'Added new app ' + handler.appId + ' from push';
- console.log(msg);
- notifier.success(msg);
- }).then(function() {
- // Reload so the app is visible while it's updating (below).
- return $scope.loadAppsList().then(function() {
- return handler;
- });
- });
- }
-
- var theApp;
- promise.then(function(app) {
- theApp = app;
- return AppsService.updateApp(app);
- }).then(function() {
- notifier.success('Updated ' + theApp.appId + ' due to remote push.');
- return $scope.loadAppsList();
- }).then(function() {
- return $scope.launchApp(theApp, { stopPropagation: function() { } });
- }).done(null, function(err) {
- var msg = 'Failed to update ' + app.appId + ': ' + err;
- console.error(msg);
- notifier.error(msg);
- });
- });
- }
- });
-
- $scope.listen = function() {
- appharness.push.listen(function() {
- $scope.listening = true;
- $scope.$apply();
- }, notifier.error);
- };
- }
}]);
})();
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/afdd006f/www/cdvah/views/list.html
----------------------------------------------------------------------
diff --git a/www/cdvah/views/list.html b/www/cdvah/views/list.html
index f49de77..aa368b8 100644
--- a/www/cdvah/views/list.html
+++ b/www/cdvah/views/list.html
@@ -21,8 +21,7 @@
<button class="topcoat-button" ng-click="loadAppsList()">Reload</button>
</div>
-<div class="listen" ng-show="listening !== undefined">
- <button class="topcoat-button" ng-show="!listening" ng-click="listen()">Start listening</button>
- <div ng-show="listening">Listening. IP=<strong>{{ipAddress}}</strong></div>
+<div class="listen" ng-show="listening">
+ Listening. IP = <strong>{{ipAddress}}</strong>
</div>