use capacitor AppLauncher instead of Browser

This commit is contained in:
Paul Miller
2023-11-10 16:43:11 -06:00
committed by Tony Giorgio
parent 761222c85e
commit 2c4c37c23f
9 changed files with 45 additions and 45 deletions

View File

@@ -1,13 +1,19 @@
import { Browser } from "@capacitor/browser";
import { Capacitor } from "@capacitor/core";
import { AppLauncher } from '@capacitor/app-launcher';
// Safari is a jerk and is aggressive about blocking window.open calls if the logic is too complex
// Capacitor should be doing this for us but \o/
export function openLinkProgrammatically(href?: string) {
if (!href) return;
export async function openLinkProgrammatically(url?: string) {
if (!url) return;
if (Capacitor.isNativePlatform()) {
Browser.open({ url: href || "", windowName: "_blank" });
const { value } = await AppLauncher.canOpenUrl({ url });
if (!value) {
// Try to open in browser just in case that works glhf
window.open(url || "", "_blank");
return;
} else {
await AppLauncher.openUrl({ url});
}
} else {
window.open(href || "", "_blank");
window.open(url || "", "_blank");
}
}