From 3e4b85d8aa1cba276b7930e6bf4ccbc7785c0124 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 29 Jun 2022 11:51:07 -0300 Subject: [PATCH] Checks if browser was exited before calling executescript again. --- src/store/storeWp.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/store/storeWp.ts b/src/store/storeWp.ts index e70e920..4d6895b 100644 --- a/src/store/storeWp.ts +++ b/src/store/storeWp.ts @@ -88,7 +88,7 @@ const useWpStore = defineStore("wp", { this.userLogin = await store.get("userLogin"); this.userToken = await store.get("userToken"); }, - createInAppBrowser(url = '',extraParams = 'location=no,fullscreen=no,zoom=no') { + createInAppBrowser(url = '',extraParams = 'location=yes,hideurlbar=yes,fullscreen=no,zoom=no,hardwareback=no,toolbarcolor=#ffffff') { let tainacanAdminUrl = this.userSiteUrl + "/wp-admin/admin.php?page=tainacan_admin&mobileAppMode=true&itemEditionMode=true" + url; if (!this.userIsLoggedIn && this.authorizationURL) tainacanAdminUrl = this.authorizationURL + "?app_name=TainacanMobileApp&success_url=" + tainacanAdminUrl; @@ -99,15 +99,19 @@ const useWpStore = defineStore("wp", { openInAppBrowser(url: string) { if (!this.inAppBrowser || !this.inAppBrowser.executeScript) - this.createInAppBrowser('#' + url, 'hidden=yes,location=no,fullscreen=no,zoom=no'); + this.createInAppBrowser('#' + url, 'hidden=yes,location=yes,hideurlbar=yes,fullscreen=no,zoom=no,hardwareback=no,toolbarcolor=#ffffff'); else { const urlRedirectionScript = ` + try { window.history.replaceState( null, null, '${this.userSiteUrl}/wp-admin/admin.php?page=tainacan_admin&mobileAppMode=true&itemEditionMode=true#${url}' ); window.history.go(0); + } catch(err){ + console.log('catch', err); + } `; this.inAppBrowser.executeScript({ code: urlRedirectionScript }); } @@ -119,6 +123,9 @@ const useWpStore = defineStore("wp", { }, listenEventInAppBrowser(event: any) { this.inAppBrowser.on('message').subscribe(event); + this.inAppBrowser.on('exit').subscribe((anEvent: any) => { + delete this.inAppBrowser; + }) } }, });