From 9cea58584a4290304e534ea61661c1659d4ca9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Wed, 9 Dec 2015 17:26:16 -0300 Subject: [PATCH 1/4] second back button press to exit --- src/js/init.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/js/init.js b/src/js/init.js index fd7eee3d8..884c2b8e2 100644 --- a/src/js/init.js +++ b/src/js/init.js @@ -24,6 +24,10 @@ angular.element(document).ready(function() { if (window.cordova !== undefined) { document.addEventListener('deviceready', function() { + var exitApp = false, + intval = setInterval(function() { + exitApp = false; + }, 2000); document.addEventListener('pause', function() { if (!window.ignoreMobilePause) { @@ -45,17 +49,24 @@ 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; + 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; + } + 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() { From dd68836eeafd40eca48863c15777cc1defa42028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Thu, 10 Dec 2015 09:59:56 -0300 Subject: [PATCH 2/4] fixing bugs --- src/js/init.js | 37 +++++++++++++++++++------------------ src/js/routes.js | 9 +++++++-- 2 files changed, 26 insertions(+), 20 deletions(-) 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'); } From 682c896f27cbe5e416bcf2abdeae17130b1eaac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Thu, 10 Dec 2015 11:24:42 -0300 Subject: [PATCH 3/4] rename and more seconds to the interval --- src/js/init.js | 12 ++++++------ src/js/routes.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/js/init.js b/src/js/init.js index b7eb360fc..cad48be92 100644 --- a/src/js/init.js +++ b/src/js/init.js @@ -25,10 +25,10 @@ angular.element(document).ready(function() { document.addEventListener('deviceready', function() { - var exitApp = 'false'; + var secondBackButtonPress = 'false'; var intval = setInterval(function() { - exitApp = 'false'; - }, 2000); + secondBackButtonPress = 'false'; + }, 5000); document.addEventListener('pause', function() { if (!window.ignoreMobilePause) { @@ -58,11 +58,11 @@ angular.element(document).ready(function() { if (exit != 'true') var exit = loc.toString().match(/index\.html#\/$/) ? 'true' : ''; if (!window.ignoreMobilePause) { - window.location = '#/cordova/backbutton/' + exit + '/' + exitApp; - if (exitApp == 'true') { + window.location = '#/cordova/backbutton/' + exit + '/' + secondBackButtonPress; + if (secondBackButtonPress == 'true') { clearInterval(intval); } else { - exitApp = 'true'; + secondBackButtonPress = 'true'; } } setTimeout(function() { diff --git a/src/js/routes.js b/src/js/routes.js index b14a08e77..8df3986c1 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -475,7 +475,7 @@ angular } }) .state('cordova', { - url: '/cordova/:status/:exit/:exitApp', + url: '/cordova/:status/:exit/:secondBackButtonPress', views: { 'main': { controller: function($rootScope, $state, $stateParams, $timeout, go, isCordova) { @@ -486,7 +486,7 @@ angular break; case 'backbutton': if (isCordova && $stateParams.exit == 'true' && !$rootScope.modalOpened) { - if ($stateParams.exitApp == 'true') { + if ($stateParams.secondBackButtonPress == 'true') { navigator.app.exitApp(); } else { window.plugins.toast.showShortBottom('Press again to exit'); From 5c715684b731d3a1e14d51ad661b4274f001f266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Thu, 10 Dec 2015 12:10:36 -0300 Subject: [PATCH 4/4] resume and pause event bug --- src/js/init.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/init.js b/src/js/init.js index cad48be92..7d8ff08bd 100644 --- a/src/js/init.js +++ b/src/js/init.js @@ -33,7 +33,7 @@ angular.element(document).ready(function() { document.addEventListener('pause', function() { if (!window.ignoreMobilePause) { setTimeout(function() { - window.location = '#/cordova/pause/'; + window.location = '#/cordova/pause//'; }, 100); } }, false); @@ -41,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() {