diff --git a/src/js/init.js b/src/js/init.js index 4acdcfdc0..c241d99b1 100644 --- a/src/js/init.js +++ b/src/js/init.js @@ -25,10 +25,15 @@ 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/'; + window.location = '#/cordova/pause//'; }, 100); } }, false); @@ -36,7 +41,7 @@ angular.element(document).ready(function() { document.addEventListener('resume', function() { if (!window.ignoreMobilePause) { setTimeout(function() { - window.location = '#/cordova/resume/'; + window.location = '#/cordova/resume//'; }, 100); } setTimeout(function() { @@ -45,13 +50,20 @@ angular.element(document).ready(function() { }, false); // Back button event + document.addEventListener('backbutton', function() { + var loc = window.location; var exit = loc.toString().match(/disclaimer/) ? 'true' : ''; if (exit != 'true') var exit = loc.toString().match(/index\.html#\/$/) ? 'true' : ''; if (!window.ignoreMobilePause) { - window.location = '#/cordova/backbutton/' + exit; + window.location = '#/cordova/backbutton/' + exit + '/' + secondBackButtonPress; + if (secondBackButtonPress == 'true') { + clearInterval(intval); + } else { + secondBackButtonPress = 'true'; + } } setTimeout(function() { window.ignoreMobilePause = false; diff --git a/src/js/routes.js b/src/js/routes.js index ba34f05da..8df3986c1 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -475,17 +475,22 @@ angular } }) .state('cordova', { - url: '/cordova/:status/:exit', + url: '/cordova/:status/:exit/:secondBackButtonPress', views: { 'main': { controller: function($rootScope, $state, $stateParams, $timeout, go, isCordova) { + switch ($stateParams.status) { case 'resume': $rootScope.$emit('Local/Resume'); break; case 'backbutton': if (isCordova && $stateParams.exit == 'true' && !$rootScope.modalOpened) { - navigator.app.exitApp(); + if ($stateParams.secondBackButtonPress == 'true') { + navigator.app.exitApp(); + } else { + window.plugins.toast.showShortBottom('Press again to exit'); + } } else { $rootScope.$emit('closeModal'); }