mirror of https://github.com/BTCPrivate/copay.git
handle hardware backbutton, init ionic platform and handle cordova events with ionicPlatform directive
This commit is contained in:
parent
119b3c7642
commit
ba91319a7a
|
@ -27,60 +27,6 @@ angular.element(document).ready(function() {
|
|||
|
||||
document.addEventListener('deviceready', function() {
|
||||
|
||||
var secondBackButtonPress = 'false';
|
||||
var intval = setInterval(function() {
|
||||
secondBackButtonPress = 'false';
|
||||
}, 5000);
|
||||
|
||||
document.addEventListener('pause', function() {
|
||||
if (!window.ignoreMobilePause) {
|
||||
setTimeout(function() {
|
||||
window.location = '#/cordova/pause///';
|
||||
}, 100);
|
||||
}
|
||||
}, false);
|
||||
|
||||
document.addEventListener('resume', function() {
|
||||
if (!window.ignoreMobilePause) {
|
||||
setTimeout(function() {
|
||||
window.location = '#/cordova/resume///';
|
||||
}, 100);
|
||||
}
|
||||
setTimeout(function() {
|
||||
var loc = window.location;
|
||||
var ignoreMobilePause = loc.toString().match(/(buy|sell|buycoinbase|sellcoinbase)/) ? true : false;
|
||||
window.ignoreMobilePause = ignoreMobilePause;
|
||||
}, 100);
|
||||
}, false);
|
||||
|
||||
// Back button event
|
||||
|
||||
document.addEventListener('backbutton', function() {
|
||||
|
||||
var loc = window.location;
|
||||
var fromDisclaimer = loc.toString().match(/disclaimer/) ? 'true' : '';
|
||||
var fromHome = loc.toString().match(/index\.html#\/$/) ? 'true' : '';
|
||||
if (!window.ignoreMobilePause) {
|
||||
window.location = '#/cordova/backbutton/' + fromHome + '/' + fromDisclaimer + '/' + secondBackButtonPress;
|
||||
if (secondBackButtonPress == 'true') {
|
||||
clearInterval(intval);
|
||||
} else {
|
||||
secondBackButtonPress = 'true';
|
||||
}
|
||||
}
|
||||
setTimeout(function() {
|
||||
window.ignoreMobilePause = false;
|
||||
}, 100);
|
||||
}, false);
|
||||
|
||||
document.addEventListener('menubutton', function() {
|
||||
window.location = '#/preferences';
|
||||
}, false);
|
||||
|
||||
setTimeout(function() {
|
||||
navigator.splashscreen.hide();
|
||||
}, 1000);
|
||||
|
||||
window.plugins.webintent.getUri(handleBitcoinURI);
|
||||
window.plugins.webintent.onNewIntent(handleBitcoinURI);
|
||||
window.handleOpenURL = handleBitcoinURI;
|
||||
|
@ -96,6 +42,7 @@ angular.element(document).ready(function() {
|
|||
|
||||
startAngular();
|
||||
}, false);
|
||||
|
||||
} else {
|
||||
try {
|
||||
window.handleOpenURL = handleBitcoinURI;
|
||||
|
|
117
src/js/routes.js
117
src/js/routes.js
|
@ -20,12 +20,12 @@ angular
|
|||
$urlRouterProvider.otherwise('/');
|
||||
|
||||
$logProvider.debugEnabled(true);
|
||||
$provide.decorator('$log', ['$delegate', 'platformInfo',
|
||||
function($delegate, platformInfo) {
|
||||
$provide.decorator('$log', ['$delegate', 'isDevel',
|
||||
function($delegate, isDevel) {
|
||||
var historicLog = historicLogProvider.$get();
|
||||
|
||||
['debug', 'info', 'warn', 'error', 'log'].forEach(function(level) {
|
||||
if (platformInfo.isDevel && level == 'error') return;
|
||||
if (isDevel && level == 'error') return;
|
||||
|
||||
var orig = $delegate[level];
|
||||
$delegate[level] = function() {
|
||||
|
@ -521,49 +521,86 @@ angular
|
|||
templateUrl: 'views/add.html'
|
||||
},
|
||||
}
|
||||
})
|
||||
.state('cordova', {
|
||||
url: '/cordova/:status/:fromHome/:fromDisclaimer/:secondBackButtonPress',
|
||||
views: {
|
||||
'main': {
|
||||
controller: function($rootScope, $state, $stateParams, $timeout, go, platformInfo, gettextCatalog) {
|
||||
|
||||
switch ($stateParams.status) {
|
||||
case 'resume':
|
||||
$rootScope.$emit('Local/Resume');
|
||||
break;
|
||||
case 'backbutton':
|
||||
|
||||
if ($stateParams.fromDisclaimer == 'true')
|
||||
navigator.app.exitApp();
|
||||
|
||||
if (platformInfo.isCordova && $stateParams.fromHome == 'true' && !$rootScope.modalOpened) {
|
||||
if ($stateParams.secondBackButtonPress == 'true') {
|
||||
navigator.app.exitApp();
|
||||
} else {
|
||||
window.plugins.toast.showShortBottom(gettextCatalog.getString('Press again to exit'));
|
||||
}
|
||||
} else {
|
||||
$rootScope.$emit('closeModal');
|
||||
}
|
||||
break;
|
||||
};
|
||||
$timeout(function() {
|
||||
$rootScope.$emit('Local/SetTab', 'walletHome', true);
|
||||
}, 100);
|
||||
go.walletHome();
|
||||
}
|
||||
}
|
||||
},
|
||||
needProfile: false
|
||||
});
|
||||
})
|
||||
.run(function($rootScope, $state, $log, uriHandler, platformInfo, profileService, $timeout, uxLanguage, animationService) {
|
||||
.run(function($rootScope, $state, $log, $timeout, $ionicPlatform, uriHandler, platformInfo, profileService, uxLanguage, animationService, go, gettextCatalog) {
|
||||
|
||||
$ionicPlatform.ready(function() {
|
||||
if (window.cordova !== undefined) {
|
||||
|
||||
$ionicPlatform.registerBackButtonAction(function(event) {
|
||||
event.preventDefault();
|
||||
}, 100);
|
||||
|
||||
var secondBackButtonPress = 'false';
|
||||
var intval = setInterval(function() {
|
||||
secondBackButtonPress = 'false';
|
||||
}, 5000);
|
||||
|
||||
$ionicPlatform.on('pause', function() {
|
||||
// Nothing to do
|
||||
});
|
||||
|
||||
$ionicPlatform.on('resume', function() {
|
||||
if (!window.ignoreMobilePause) {
|
||||
$rootScope.$emit('Local/Resume');
|
||||
}
|
||||
setTimeout(function() {
|
||||
var loc = window.location;
|
||||
var ignoreMobilePause = loc.toString().match(/(buy|sell|buycoinbase|sellcoinbase)/) ? true : false;
|
||||
window.ignoreMobilePause = ignoreMobilePause;
|
||||
}, 100);
|
||||
});
|
||||
|
||||
$ionicPlatform.on('backbutton', function(event) {
|
||||
|
||||
var loc = window.location;
|
||||
var fromDisclaimer = loc.toString().match(/disclaimer/) ? 'true' : '';
|
||||
var fromHome = loc.toString().match(/index\.html#\/$/) ? 'true' : '';
|
||||
|
||||
if (fromDisclaimer == 'true')
|
||||
navigator.app.exitApp();
|
||||
|
||||
if (platformInfo.isMobile && fromHome == 'true' && !$rootScope.modalOpened) {
|
||||
if (secondBackButtonPress == 'true') {
|
||||
navigator.app.exitApp();
|
||||
} else {
|
||||
window.plugins.toast.showShortBottom(gettextCatalog.getString('Press again to exit'));
|
||||
}
|
||||
} else {
|
||||
$rootScope.$emit('closeModal');
|
||||
}
|
||||
|
||||
if (secondBackButtonPress == 'true') {
|
||||
clearInterval(intval);
|
||||
} else {
|
||||
secondBackButtonPress = 'true';
|
||||
}
|
||||
|
||||
$timeout(function() {
|
||||
$rootScope.$emit('Local/SetTab', 'walletHome', true);
|
||||
}, 100);
|
||||
go.walletHome();
|
||||
|
||||
setTimeout(function() {
|
||||
window.ignoreMobilePause = false;
|
||||
}, 100);
|
||||
});
|
||||
|
||||
$ionicPlatform.on('menubutton', function() {
|
||||
window.location = '#/preferences';
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
navigator.splashscreen.hide();
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
uxLanguage.init();
|
||||
|
||||
// Register URI handler, not for mobileApp
|
||||
if (!platformInfo.isCordova) {
|
||||
if (!platformInfo.isMobile) {
|
||||
uriHandler.register();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue