From 2c900f6416d98c5dcab75f37b29ba8a3d5335a8b Mon Sep 17 00:00:00 2001 From: arzynik Date: Wed, 29 Oct 2014 15:51:35 -0700 Subject: [PATCH] error catching --- www/assets/cockpit/js/cockpit.js | 8 ++++---- www/assets/cockpit/js/service.heartbeat.js | 4 ++-- www/assets/cockpit/js/service.location.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/www/assets/cockpit/js/cockpit.js b/www/assets/cockpit/js/cockpit.js index 13f046ce4..598b1310c 100644 --- a/www/assets/cockpit/js/cockpit.js +++ b/www/assets/cockpit/js/cockpit.js @@ -516,8 +516,8 @@ NGApp.run( function ( $rootScope, $location, MainNavigationService ) { App.alert = function(txt, title, useNativeAlert, fn) { setTimeout(function() { - if (useNativeAlert && App.isPhoneGap) { - parent.navigator.notification.alert(txt, null, title || 'Crunchbutton'); + if (useNativeAlert && App.isPhoneGap && parent.window.navigator && parent.window.navigator.notification) { + parent.window.navigator.notification.alert(txt, null, title || 'Crunchbutton'); } else if ( useNativeAlert ) { alert( txt ); } else { @@ -527,8 +527,8 @@ App.alert = function(txt, title, useNativeAlert, fn) { }; App.confirm = function(txt, title, fn, buttons) { - if (App.useNativeConfirm && App.isPhoneGap) { - return navigator.notification.confirm(txt, fn, title || 'Crunchbutton', buttons || 'Ok,Cancel' ); + if (App.useNativeConfirm && App.isPhoneGap && parent.window.navigator && parent.window.navigator.notification) { + return parent.window.navigator.notification.confirm(txt, fn, title || 'Crunchbutton', buttons || 'Ok,Cancel' ); } else { return confirm(txt); } diff --git a/www/assets/cockpit/js/service.heartbeat.js b/www/assets/cockpit/js/service.heartbeat.js index 563310ba3..cca4d532a 100644 --- a/www/assets/cockpit/js/service.heartbeat.js +++ b/www/assets/cockpit/js/service.heartbeat.js @@ -34,7 +34,7 @@ NGApp.factory('HeartbeatService', function($rootScope, $resource, $interval, Loc service.load(function(data) { service.date = new Date; - if (App.isPhoneGap) { + if (App.isPhoneGap && parent.plugins && parent.plugins.pushNotification) { var complete = function(){}; PushService.badges = parseInt(data.tickets) + parseInt(data.orders['new']); parent.plugins.pushNotification.setApplicationIconBadgeNumber(complete, complete, PushService.badges); @@ -56,7 +56,7 @@ NGApp.factory('HeartbeatService', function($rootScope, $resource, $interval, Loc $rootScope.$on('appResume', service.check); $rootScope.$on('appPause', function() { - if (App.isPhoneGap) { + if (App.isPhoneGap && parent.plugins && parent.plugins.pushNotification) { var complete = function(){}; parent.plugins.pushNotification.setApplicationIconBadgeNumber(complete, complete, PushService.badges); } diff --git a/www/assets/cockpit/js/service.location.js b/www/assets/cockpit/js/service.location.js index c4d6b41c3..45baf01e2 100644 --- a/www/assets/cockpit/js/service.location.js +++ b/www/assets/cockpit/js/service.location.js @@ -4,7 +4,7 @@ NGApp.factory('LocationService', function($http, $resource, $rootScope) { - if (App.isPhoneGap) { + if (App.isPhoneGap && parent.window.plugins && parent.window.plugins.backgroundGeoLocation) { var bgGeo = parent.window.plugins.backgroundGeoLocation; @@ -101,7 +101,7 @@ NGApp.factory('LocationService', function($http, $resource, $rootScope) { //alert('Your location services are off, or you declined location permissions. Please enable this.'); }, { enableHighAccuracy: true }); } - if (App.isPhoneGap) { + if (App.isPhoneGap && bgGeo) { bgGeo.start(); } }; @@ -123,7 +123,7 @@ NGApp.factory('LocationService', function($http, $resource, $rootScope) { parent.window.navigator.geolocation.clearWatch(watcher); watcher = null; - if (App.isPhoneGap) { + if (App.isPhoneGap && bgGeo) { bgGeo.stop(); } }