diff --git a/src/routes/settings/Connections.tsx b/src/routes/settings/Connections.tsx index fbdfa8f..a51c479 100644 --- a/src/routes/settings/Connections.tsx +++ b/src/routes/settings/Connections.tsx @@ -1,4 +1,3 @@ -import { Browser } from "@capacitor/browser"; import { NwcProfile, type BudgetPeriod } from "@mutinywallet/mutiny-wasm"; import { createEffect, @@ -34,7 +33,7 @@ import { import { BudgetForm, NWCBudgetEditor } from "~/components/NWCBudgetEditor"; import { useI18n } from "~/i18n/context"; import { useMegaStore } from "~/state/megaStore"; -import { createDeepSignal } from "~/utils"; +import { createDeepSignal, openLinkProgrammatically } from "~/utils"; function mapIntervalToBudgetPeriod( interval: "Day" | "Week" | "Month" | "Year" @@ -112,13 +111,13 @@ function NwcDetails(props: { function openInNostrClient() { const uri = props.profile.nwc_uri; - Browser.open({ url: uri }); + openLinkProgrammatically(uri); } function openInPrimal() { const uri = props.profile.nwc_uri; const connectString = uri.replace("nostr+walletconnect", "primal"); - Browser.open({ url: connectString }); + openLinkProgrammatically(connectString); } return ( @@ -197,7 +196,7 @@ function Nwc() { const [searchParams, setSearchParams] = useSearchParams(); const queryName = searchParams.name; const [callbackDialogOpen, setCallbackDialogOpen] = createSignal(false); - const [callbackUri, setCallbackUri] = createSignal(null); + const [callbackUri, setCallbackUri] = createSignal(); // Profile creation / editing const [dialogOpen, setDialogOpen] = createSignal(!!queryName); @@ -279,11 +278,9 @@ function Nwc() { } function openCallbackUri() { - if (callbackUri()) { - Browser.open({ url: callbackUri() as string }); - setSearchParams({ callbackUri: "" }); - setCallbackDialogOpen(false); - } + openLinkProgrammatically(callbackUri()); + setSearchParams({ callbackUri: "" }); + setCallbackDialogOpen(false); } return ( diff --git a/src/utils/index.ts b/src/utils/index.ts index 02f2950..cf26dab 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -15,3 +15,4 @@ export * from "./typescript"; export * from "./useCopy"; export * from "./words"; export * from "./fetchZaps"; +export * from "./openLinkProgrammatically"; diff --git a/src/utils/openLinkProgrammatically.ts b/src/utils/openLinkProgrammatically.ts new file mode 100644 index 0000000..277c132 --- /dev/null +++ b/src/utils/openLinkProgrammatically.ts @@ -0,0 +1,13 @@ +import { Browser } from "@capacitor/browser"; +import { Capacitor } from "@capacitor/core"; + +// 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; + if (Capacitor.isNativePlatform()) { + Browser.open({ url: href || "", windowName: "_blank" }); + } else { + window.open(href || "", "_blank"); + } +}