From bc74ba361cc9b84804c8afd46ce9bbbe325e109c Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 10 Sep 2021 00:49:55 -0600 Subject: [PATCH] Browser improvements --- www/assets/js/account.js | 16 ++++++++++++++-- www/assets/js/platform.js | 24 ++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/www/assets/js/account.js b/www/assets/js/account.js index 160923f..55d68f5 100644 --- a/www/assets/js/account.js +++ b/www/assets/js/account.js @@ -257,6 +257,18 @@ function openCheckoutWindowToSaveCard() { openBrowser(SETTINGS.apis.redirecttopaymentsetup + "?phone=" + getStorage("phonenumber") + "&accountkey=" + getStorage("accountkey"), - "location=no" - ); + "location=yes", + function () { + // on exit browser + initAccountPage(); + }, + function (params) { + // on get message from browser + // only message we should get is "kill me" + if (params.data.my_message == "kill me") { + initAccountPage(); + closeBrowser(); + } + } + ); } \ No newline at end of file diff --git a/www/assets/js/platform.js b/www/assets/js/platform.js index b8df05c..c618ddb 100644 --- a/www/assets/js/platform.js +++ b/www/assets/js/platform.js @@ -18,10 +18,16 @@ var nw_tray = null; */ var auto_disable_animations = false; +var cordovaInAppBrowserRef = null; + var openBrowser = function (url) { window.open(url); } +var closeBrowser = function () { + // stub +} + var openSystemBrowser = function (url) { window.open(url); } @@ -172,11 +178,25 @@ function initCordova() { window.htmlopen = window.open; window.open = cordova.InAppBrowser.open; - openBrowser = function (url, options) { + openBrowser = function (url, options, onclose, onmessage) { if (typeof options == "undefined") { options = "location=yes"; } - window.open(url, '_blank', options); + cordovaInAppBrowserRef = cordova.InAppBrowser.open(url, "_blank", options); + if (typeof onclose == "function") { + cordovaInAppBrowserRef.removeEventListener("exit"); + cordovaInAppBrowserRef.addEventListener("exit", onclose); + } + if (typeof onmessage == "function") { + cordovaInAppBrowserRef.removeEventListener("message"); + cordovaInAppBrowserRef.addEventListener("message", onmessage); + } + } + + closeBrowser = function () { + if (typeof cordovaInAppBrowserRef != null) { + cordovaInAppBrowserRef.close(); + } } openExternalBrowser = function (url) {