.run(function($ionicPlatform, $rootScope, $location, $ionicHistory, $cordovaToast, $timeout) {
$ionicPlatform.registerBackButtonAction(function (e) {
e.preventDefault();
// Is there a page to go back to?
if ($location.path() == '/main' ) {
if ($rootScope.backButtonPressedOnceToExit) {
ionic.Platform.exitApp();
} else {
$rootScope.backButtonPressedOnceToExit = true;
$cordovaToast.showShortTop('Press again to exit APP.');
setTimeout(function () {
$rootScope.backButtonPressedOnceToExit = false;
}, 2000);
}
} else if ($ionicHistory.backView()) {
$ionicHistory.goBack();
} else {
// This is the last page
$rootScope.backButtonPressedOnceToExit = true;
$cordovaToast.showShortTop('Press again to exit APP.');
setTimeout(function () {
$rootScope.backButtonPressedOnceToExit = false;
}, 2000);
}
return false;
}, 101);
})