Fix app initialisation

This commit is contained in:
Gustavo Maximiliano Cortez 2017-02-20 11:55:48 -03:00
commit d27a77cb1f
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF

View file

@ -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) {