diff --git a/cordova/build.sh b/cordova/build.sh index c4be3d920..b171a68f6 100755 --- a/cordova/build.sh +++ b/cordova/build.sh @@ -103,13 +103,10 @@ if [ ! -d $PROJECT ]; then cordova plugin add cordova-plugin-statusbar checkOK - cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME=bitcoin - checkOK - cordova plugin add phonegap-plugin-push@1.2.3 checkOK - cordova plugin add https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin.git --variable URL_SCHEME=bitcoin + cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME=bitcoin checkOK cordova plugin add cordova-plugin-inappbrowser diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index cd82e3482..17a43609e 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -5,6 +5,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r var SOFT_CONFIRMATION_LIMIT = 12; self.isCordova = isCordova; self.isChromeApp = isChromeApp; + self.usePushNotifications = isMobile.iOS() || isMobile.Android(); self.isSafari = isMobile.Safari(); self.onGoingProcess = {}; self.historyShowLimit = 10; @@ -12,13 +13,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.prevState = 'walletHome'; document.addEventListener('deviceready', function() { - if (isMobile.Android() || isMobile.iOS()) { - storageService.getDeviceToken(function(err, token) { - $timeout(function() { - if (!token) pushNotificationsService.pushNotificationsInit(); - }, 5000); - }); - } + storageService.getDeviceToken(function(err, token) { + $timeout(function() { + if (!token) pushNotificationsService.pushNotificationsInit(); + }, 5000); + }); }); function strip(number) { @@ -1075,11 +1074,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); }; - self.setUxLanguage = function() { + self.setUxLanguage = function(cb) { uxLanguage.update(function(lang) { var userLang = lang; self.defaultLanguageIsoCode = userLang; self.defaultLanguageName = uxLanguage.getName(userLang); + if (cb) return cb(); }); }; @@ -1285,13 +1285,17 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); $rootScope.$on('Local/SubscribeNotifications', function(event) { + pushNotificationsService.enableNotifications(); + }); $rootScope.$on('Local/UnsubscribeNotifications', function(event, walletId, cb) { - pushNotificationsService.unsubscribe(walletId, function(err, response) { - if (err) $log.warn('Error: ' + err.code); - $log.debug('Unsubscribed: ' + response); + if (!self.usePushNotifications) return cb(); + + pushNotificationsService.unsubscribe(walletId, function(err) { + if (err) $log.warn('Subscription error: ' + err.code); + else $log.debug('Unsubscribed from push notifications service'); return cb(); }); }); @@ -1430,7 +1434,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.noFocusedWallet = true; self.isComplete = null; self.walletName = null; - self.setUxLanguage(function() {}); + self.setUxLanguage(); profileService.isDisclaimerAccepted(function(v) { if (v) { go.path('import'); @@ -1440,7 +1444,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); $rootScope.$on('Local/NewFocusedWallet', function() { - self.setUxLanguage(function() {}); + self.setUxLanguage(); self.setFocusedWallet(); self.debounceUpdateHistory(); self.isDisclaimerAccepted(); diff --git a/src/js/services/pushNotificationsService.js b/src/js/services/pushNotificationsService.js index d53de26fc..2e7292e6b 100644 --- a/src/js/services/pushNotificationsService.js +++ b/src/js/services/pushNotificationsService.js @@ -3,8 +3,11 @@ angular.module('copayApp.services') .factory('pushNotificationsService', function($http, $log, isMobile, profileService, storageService, configService, lodash) { var root = {}; var defaults = configService.getDefaults(); + var usePushNotifications = isMobile.iOS() || isMobile.Android(); root.pushNotificationsInit = function() { + if (!usePushNotifications) return; + var push = PushNotification.init(defaults.pushNotifications.config); push.on('registration', function(data) { @@ -31,29 +34,34 @@ angular.module('copayApp.services') }; root.enableNotifications = function() { + if (!usePushNotifications) return; + storageService.getDeviceToken(function(err, token) { lodash.forEach(profileService.getWallets('testnet'), function(wallet) { var opts = {}; opts.type = isMobile.iOS() ? "ios" : isMobile.Android() ? "android" : null; opts.token = token; root.subscribe(opts, wallet.id, function(err, response) { - if (err) $log.warn('Error: ' + err.code); - $log.debug('Suscribed to push notifications service: ' + JSON.stringify(response)); + if (err) $log.warn('Subscription error: ' + err.code); + else $log.debug('Subscribed to push notifications service: ' + JSON.stringify(response)); }); }); }); } root.disableNotifications = function() { + if (!usePushNotifications) return; + lodash.forEach(profileService.getWallets('testnet'), function(wallet) { - root.unsubscribe(wallet.id, function(err, response) { - if (err) $log.warn('Error: ' + err.code); - $log.debug('Unsubscribed from push notifications service'); + root.unsubscribe(wallet.id, function(err) { + if (err) $log.warn('Subscription error: ' + err.code); + else $log.debug('Unsubscribed from push notifications service'); }); }); } root.subscribe = function(opts, walletId, cb) { + var walletClient = profileService.getClient(walletId); walletClient.pushNotificationsSubscribe(opts, function(err, resp) { if (err) return cb(err); @@ -62,10 +70,11 @@ angular.module('copayApp.services') } root.unsubscribe = function(walletId, cb) { + var walletClient = profileService.getClient(walletId); - walletClient.pushNotificationsUnsubscribe(function(err, resp) { + walletClient.pushNotificationsUnsubscribe(function(err) { if (err) return cb(err); - return cb(null, resp); + return cb(null); }); }