cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bra...@apache.org
Subject [6/6] git commit: Only run push-related code when the plugin exists.
Date Mon, 27 Jan 2014 16:04:21 GMT
Only run push-related code when the plugin exists.


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

Branch: refs/heads/master
Commit: 5156ee43ab4fc8c8b00d48cc2710dd9ef6600366
Parents: 018bdd1
Author: Braden Shepherdson <braden.shepherdson@gmail.com>
Authored: Fri Jan 24 15:10:08 2014 -0500
Committer: Braden Shepherdson <braden.shepherdson@gmail.com>
Committed: Mon Jan 27 11:01:27 2014 -0500

----------------------------------------------------------------------
 www/cdvah/js/ListCtrl.js | 108 +++++++++++++++++++++---------------------
 1 file changed, 55 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/5156ee43/www/cdvah/js/ListCtrl.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/ListCtrl.js b/www/cdvah/js/ListCtrl.js
index b74c953..a73aa1f 100644
--- a/www/cdvah/js/ListCtrl.js
+++ b/www/cdvah/js/ListCtrl.js
@@ -21,7 +21,7 @@
                             notifier.error('' + e);
                         });
                     } else if (action == 'update') {
-                        // updating may take a while so we show the apps list like we normally
do
+                        // Updating may take a while so we show the apps list like we normally
do
                         return AppsService.updateApp(activeApp)
                         .then(function() {
                             return AppsService.launchApp(activeApp);
@@ -99,63 +99,65 @@
 
         initialise();
 
-        appharness.push.listening(function(res) {
-            $scope.listening = res;
-            $scope.$apply();
-        }, notifier.error);
+        if (appharness && appharness.push) {
+            appharness.push.listening(function(res) {
+                $scope.listening = res;
+                $scope.$apply();
+            }, notifier.error);
 
-        appharness.push.pending(function(obj) {
-            console.log('Return from pending: ' + obj);
-            if (obj && obj.type && obj.type === 'serve') {
-                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;
+            appharness.push.pending(function(obj) {
+                console.log('Return from pending: ' + obj);
+                if (obj && obj.type && obj.type === 'serve') {
+                    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();
-                    }).done(function() {
-                        $scope.launchApp(theApp, { stopPropagation: function() { } });
-                    }, function(err) {
-                        var msg = 'Failed to update ' + app.appId + ': ' + err;
-                        console.error(msg);
-                        notifier.error(msg);
+                        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);
-        };
+            $scope.listen = function() {
+                appharness.push.listen(function() {
+                    $scope.listening = true;
+                    $scope.$apply();
+                }, notifier.error);
+            };
+        }
     }]);
 })();
 


Mime
View raw message