From 1d3e74164df94a4e11f29d31e2b09c11d4ef36b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Wed, 20 Jan 2016 15:28:56 -0300 Subject: [PATCH 1/4] adding control for non ios and android device in pushnotifications registration --- cordova/build.sh | 5 +---- src/js/controllers/index.js | 7 +++++-- 2 files changed, 6 insertions(+), 6 deletions(-) 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..a7fc1c4b4 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.pushDeviceType = isMobile.iOS() || isMobile.Android(); self.isSafari = isMobile.Safari(); self.onGoingProcess = {}; self.historyShowLimit = 10; @@ -12,7 +13,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.prevState = 'walletHome'; document.addEventListener('deviceready', function() { - if (isMobile.Android() || isMobile.iOS()) { + if (self.pushDeviceType) { storageService.getDeviceToken(function(err, token) { $timeout(function() { if (!token) pushNotificationsService.pushNotificationsInit(); @@ -1285,7 +1286,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); $rootScope.$on('Local/SubscribeNotifications', function(event) { - pushNotificationsService.enableNotifications(); + if (self.pushDeviceType) { + pushNotificationsService.enableNotifications(); + } }); $rootScope.$on('Local/UnsubscribeNotifications', function(event, walletId, cb) { From a53ba1fea0717bba3d609dfcf8bfbaef2e59ede6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Wed, 20 Jan 2016 16:06:15 -0300 Subject: [PATCH 2/4] refactor --- src/js/controllers/index.js | 25 ++++++++++++--------- src/js/services/pushNotificationsService.js | 11 +++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index a7fc1c4b4..18f2eee90 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -5,7 +5,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r var SOFT_CONFIRMATION_LIMIT = 12; self.isCordova = isCordova; self.isChromeApp = isChromeApp; - self.pushDeviceType = isMobile.iOS() || isMobile.Android(); + self.usePushNotifications = isMobile.iOS() || isMobile.Android(); self.isSafari = isMobile.Safari(); self.onGoingProcess = {}; self.historyShowLimit = 10; @@ -13,13 +13,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.prevState = 'walletHome'; document.addEventListener('deviceready', function() { - if (self.pushDeviceType) { - storageService.getDeviceToken(function(err, token) { - $timeout(function() { - if (!token) pushNotificationsService.pushNotificationsInit(); - }, 5000); - }); - } + if (!self.usePushNotifications) return; + + storageService.getDeviceToken(function(err, token) { + $timeout(function() { + if (!token) pushNotificationsService.pushNotificationsInit(); + }, 5000); + }); }); function strip(number) { @@ -1286,12 +1286,15 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); $rootScope.$on('Local/SubscribeNotifications', function(event) { - if (self.pushDeviceType) { - pushNotificationsService.enableNotifications(); - } + if (!self.usePushNotifications) return; + + pushNotificationsService.enableNotifications(); + }); $rootScope.$on('Local/UnsubscribeNotifications', function(event, walletId, cb) { + if (self.usePushNotifications) return cb(); + pushNotificationsService.unsubscribe(walletId, function(err, response) { if (err) $log.warn('Error: ' + err.code); $log.debug('Unsubscribed: ' + response); diff --git a/src/js/services/pushNotificationsService.js b/src/js/services/pushNotificationsService.js index d53de26fc..7f17b024e 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,6 +34,8 @@ angular.module('copayApp.services') }; root.enableNotifications = function() { + if (!usePushNotifications) return; + storageService.getDeviceToken(function(err, token) { lodash.forEach(profileService.getWallets('testnet'), function(wallet) { var opts = {}; @@ -45,6 +50,8 @@ angular.module('copayApp.services') } 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); @@ -54,6 +61,8 @@ angular.module('copayApp.services') } root.subscribe = function(opts, walletId, cb) { + if (!usePushNotifications) return; + var walletClient = profileService.getClient(walletId); walletClient.pushNotificationsSubscribe(opts, function(err, resp) { if (err) return cb(err); @@ -62,6 +71,8 @@ angular.module('copayApp.services') } root.unsubscribe = function(walletId, cb) { + if (!usePushNotifications) return; + var walletClient = profileService.getClient(walletId); walletClient.pushNotificationsUnsubscribe(function(err, resp) { if (err) return cb(err); From 6be5209fcf94ef63427a05f21ba2c42e0140eb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Wed, 20 Jan 2016 16:25:06 -0300 Subject: [PATCH 3/4] delete response in unsubscribe method --- src/js/controllers/index.js | 11 ++++------- src/js/services/pushNotificationsService.js | 16 +++++++--------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 18f2eee90..855eaed7a 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -13,8 +13,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.prevState = 'walletHome'; document.addEventListener('deviceready', function() { - if (!self.usePushNotifications) return; - storageService.getDeviceToken(function(err, token) { $timeout(function() { if (!token) pushNotificationsService.pushNotificationsInit(); @@ -1286,18 +1284,17 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); $rootScope.$on('Local/SubscribeNotifications', function(event) { - if (!self.usePushNotifications) return; pushNotificationsService.enableNotifications(); }); $rootScope.$on('Local/UnsubscribeNotifications', function(event, walletId, cb) { - if (self.usePushNotifications) return cb(); + if (!self.usePushNotifications) return cb(); - pushNotificationsService.unsubscribe(walletId, function(err, response) { - if (err) $log.warn('Error: ' + err.code); - $log.debug('Unsubscribed: ' + response); + pushNotificationsService.unsubscribe(walletId, function(err) { + if (err) $log.warn('Subscription error: ' + err.code); + else $log.debug('Unsubscribed from push notifications service'); return cb(); }); }); diff --git a/src/js/services/pushNotificationsService.js b/src/js/services/pushNotificationsService.js index 7f17b024e..2e7292e6b 100644 --- a/src/js/services/pushNotificationsService.js +++ b/src/js/services/pushNotificationsService.js @@ -42,8 +42,8 @@ angular.module('copayApp.services') 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)); }); }); }); @@ -53,15 +53,14 @@ angular.module('copayApp.services') 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) { - if (!usePushNotifications) return; var walletClient = profileService.getClient(walletId); walletClient.pushNotificationsSubscribe(opts, function(err, resp) { @@ -71,12 +70,11 @@ angular.module('copayApp.services') } root.unsubscribe = function(walletId, cb) { - if (!usePushNotifications) return; 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); }); } From 82c9e3b7311ac8dad11e0d563b5fd960125deec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Wed, 20 Jan 2016 17:21:26 -0300 Subject: [PATCH 4/4] add call back to set Ux Language --- src/js/controllers/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 855eaed7a..17a43609e 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -1074,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(); }); }; @@ -1433,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'); @@ -1443,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();