Checks if browser was exited before calling executescript again.

This commit is contained in:
mateuswetah 2022-06-29 11:51:07 -03:00
parent 045e3bafca
commit 3e4b85d8aa
1 changed files with 9 additions and 2 deletions

View File

@ -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;
})
}
},
});