diff --git a/src/js/init.js b/src/js/init.js index 884c2b8e2..b7eb360fc 100644 --- a/src/js/init.js +++ b/src/js/init.js @@ -24,10 +24,11 @@ angular.element(document).ready(function() { if (window.cordova !== undefined) { document.addEventListener('deviceready', function() { - var exitApp = false, - intval = setInterval(function() { - exitApp = false; - }, 2000); + + var exitApp = 'false'; + var intval = setInterval(function() { + exitApp = 'false'; + }, 2000); document.addEventListener('pause', function() { if (!window.ignoreMobilePause) { @@ -51,22 +52,22 @@ angular.element(document).ready(function() { // Back button event document.addEventListener('backbutton', function() { - if (exitApp) { - clearInterval(intval) - 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; + + 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 + '/' + exitApp; + if (exitApp == 'true') { + clearInterval(intval); + } else { + exitApp = 'true'; } - setTimeout(function() { - window.ignoreMobilePause = false; - }, 100); - } else { - window.plugins.toast.showShortCenter('Press again to exit'); - exitApp = true; } + setTimeout(function() { + window.ignoreMobilePause = false; + }, 100); }, false); document.addEventListener('menubutton', function() { diff --git a/src/js/routes.js b/src/js/routes.js index ba34f05da..b14a08e77 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/:exitApp', 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.exitApp == 'true') { + navigator.app.exitApp(); + } else { + window.plugins.toast.showShortBottom('Press again to exit'); + } } else { $rootScope.$emit('closeModal'); }