From d27a77cb1f058dabbb1eef41b7e82306587d708a Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Mon, 20 Feb 2017 11:55:48 -0300 Subject: [PATCH] Fix app initialisation --- src/js/routes.js | 169 +++++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 86 deletions(-) diff --git a/src/js/routes.js b/src/js/routes.js index c86c521b6..10dc45706 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -1096,101 +1096,98 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr uxLanguage.init(); $ionicPlatform.ready(function() { - if (platformInfo.isCordova) { + if (screen.width < 768) + screen.lockOrientation('portrait'); - if (screen.width < 768) - screen.lockOrientation('portrait'); - - if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) { - cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false); - cordova.plugins.Keyboard.disableScroll(true); - } - - window.addEventListener('native.keyboardshow', function() { - document.body.classList.add('keyboard-open'); - }); - - $ionicPlatform.registerBackButtonAction(function(e) { - - //from root tabs view - var matchHome = $ionicHistory.currentStateName() == 'tabs.home' ? true : false; - var matchReceive = $ionicHistory.currentStateName() == 'tabs.receive' ? true : false; - var matchScan = $ionicHistory.currentStateName() == 'tabs.scan' ? true : false; - var matchSend = $ionicHistory.currentStateName() == 'tabs.send' ? true : false; - var matchSettings = $ionicHistory.currentStateName() == 'tabs.settings' ? true : false; - var fromTabs = matchHome | matchReceive | matchScan | matchSend | matchSettings; - - //onboarding with no back views - var matchWelcome = $ionicHistory.currentStateName() == 'onboarding.welcome' ? true : false; - var matchCollectEmail = $ionicHistory.currentStateName() == 'onboarding.collectEmail' ? true : false; - var matchBackupRequest = $ionicHistory.currentStateName() == 'onboarding.backupRequest' ? true : false; - var matchNotifications = $ionicHistory.currentStateName() == 'onboarding.notifications' ? true : false; - - var fromOnboarding = matchCollectEmail | matchBackupRequest | matchNotifications | matchWelcome; - - if ($ionicHistory.backView() && !fromTabs && !fromOnboarding) { - $ionicHistory.goBack(); - } else - if ($rootScope.backButtonPressedOnceToExit) { - ionic.Platform.exitApp(); - } else { - $rootScope.backButtonPressedOnceToExit = true; - window.plugins.toast.showShortBottom(gettextCatalog.getString('Press again to exit')); - $timeout(function() { - $rootScope.backButtonPressedOnceToExit = false; - }, 3000); - } - e.preventDefault(); - }, 101); - - $ionicPlatform.on('pause', function() { - // Nothing to do - }); - - $ionicPlatform.on('resume', function() { - // Nothing to do - }); - - $ionicPlatform.on('menubutton', function() { - window.location = '#/preferences'; - }); + if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) { + cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false); + cordova.plugins.Keyboard.disableScroll(true); } - $log.info('Init profile...'); - // Try to open local profile - profileService.loadAndBindProfile(function(err) { - $ionicHistory.nextViewOptions({ - disableAnimate: true - }); - if (err) { - if (err.message && err.message.match('NOPROFILE')) { - $log.debug('No profile... redirecting'); + window.addEventListener('native.keyboardshow', function() { + document.body.classList.add('keyboard-open'); + }); + + $ionicPlatform.registerBackButtonAction(function(e) { + + //from root tabs view + var matchHome = $ionicHistory.currentStateName() == 'tabs.home' ? true : false; + var matchReceive = $ionicHistory.currentStateName() == 'tabs.receive' ? true : false; + var matchScan = $ionicHistory.currentStateName() == 'tabs.scan' ? true : false; + var matchSend = $ionicHistory.currentStateName() == 'tabs.send' ? true : false; + var matchSettings = $ionicHistory.currentStateName() == 'tabs.settings' ? true : false; + var fromTabs = matchHome | matchReceive | matchScan | matchSend | matchSettings; + + //onboarding with no back views + var matchWelcome = $ionicHistory.currentStateName() == 'onboarding.welcome' ? true : false; + var matchCollectEmail = $ionicHistory.currentStateName() == 'onboarding.collectEmail' ? true : false; + var matchBackupRequest = $ionicHistory.currentStateName() == 'onboarding.backupRequest' ? true : false; + var matchNotifications = $ionicHistory.currentStateName() == 'onboarding.notifications' ? true : false; + + var fromOnboarding = matchCollectEmail | matchBackupRequest | matchNotifications | matchWelcome; + + if ($ionicHistory.backView() && !fromTabs && !fromOnboarding) { + $ionicHistory.goBack(); + } else + if ($rootScope.backButtonPressedOnceToExit) { + ionic.Platform.exitApp(); + } else { + $rootScope.backButtonPressedOnceToExit = true; + window.plugins.toast.showShortBottom(gettextCatalog.getString('Press again to exit')); + $timeout(function() { + $rootScope.backButtonPressedOnceToExit = false; + }, 3000); + } + e.preventDefault(); + }, 101); + + $ionicPlatform.on('pause', function() { + // Nothing to do + }); + + $ionicPlatform.on('resume', function() { + // Nothing to do + }); + + $ionicPlatform.on('menubutton', function() { + window.location = '#/preferences'; + }); + }); + + $log.info('Init profile...'); + // Try to open local profile + profileService.loadAndBindProfile(function(err) { + $ionicHistory.nextViewOptions({ + disableAnimate: true + }); + if (err) { + if (err.message && err.message.match('NOPROFILE')) { + $log.debug('No profile... redirecting'); + $state.go('onboarding.welcome'); + } else if (err.message && err.message.match('NONAGREEDDISCLAIMER')) { + if (lodash.isEmpty(profileService.getWallets())) { + $log.debug('No wallets and no disclaimer... redirecting'); $state.go('onboarding.welcome'); - } else if (err.message && err.message.match('NONAGREEDDISCLAIMER')) { - if (lodash.isEmpty(profileService.getWallets())) { - $log.debug('No wallets and no disclaimer... redirecting'); - $state.go('onboarding.welcome'); - } else { - $log.debug('Display disclaimer... redirecting'); - $state.go('onboarding.disclaimer', { - resume: true - }); - } } else { - throw new Error(err); // TODO + $log.debug('Display disclaimer... redirecting'); + $state.go('onboarding.disclaimer', { + resume: true + }); } } else { - profileService.storeProfileIfDirty(); - $log.debug('Profile loaded ... Starting UX.'); - scannerService.gentleInitialize(); - $state.go('tabs.home'); + throw new Error(err); // TODO } + } else { + profileService.storeProfileIfDirty(); + $log.debug('Profile loaded ... Starting UX.'); + scannerService.gentleInitialize(); + $state.go('tabs.home'); + } - // After everything have been loaded, initialize handler URL - $timeout(function() { - openURLService.init(); - }, 1000); - }); + // After everything have been loaded, initialize handler URL + $timeout(function() { + openURLService.init(); + }, 1000); }); if (platformInfo.isNW) {