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

@@ -121,15 +121,9 @@ function NwcDetails(props: {
}
}
function openInNostrClient() {
async function openInNostrClient() {
const uri = props.profile.nwc_uri;
openLinkProgrammatically(uri);
}
function openInPrimal() {
const uri = props.profile.nwc_uri;
const connectString = uri.replace("nostr+walletconnect", "primal");
openLinkProgrammatically(connectString);
await openLinkProgrammatically(uri);
}
return (
@@ -183,13 +177,9 @@ function NwcDetails(props: {
props.profile.tag !== "Subscription"
}
>
<Button layout="small" onClick={openInNostrClient}>
<Button layout="small" intent="blue" onClick={openInNostrClient}>
{i18n.t("settings.connections.open_in_nostr_client")}
</Button>
<Button layout="small" onClick={openInPrimal}>
{i18n.t("settings.connections.open_in_primal")}
</Button>
</Show>
<Button layout="small" onClick={confirmDelete}>
@@ -317,8 +307,8 @@ function Nwc() {
}
}
function openCallbackUri() {
openLinkProgrammatically(callbackUri());
async function openCallbackUri() {
await openLinkProgrammatically(callbackUri());
setSearchParams({ callbackUri: "" });
setCallbackDialogOpen(false);
}

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");
}
}