fix(ui): open external toast links via system browser
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import toast from "solid-toast"
|
||||
import { isTauriHost } from "./runtime-env"
|
||||
|
||||
export type ToastVariant = "info" | "success" | "warning" | "error"
|
||||
|
||||
@@ -21,6 +22,31 @@ export type ToastPayload = {
|
||||
}
|
||||
}
|
||||
|
||||
async function openExternalUrl(url: string): Promise<void> {
|
||||
if (typeof window === "undefined") {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
if (isTauriHost()) {
|
||||
const { openUrl } = await import("@tauri-apps/plugin-opener")
|
||||
await openUrl(url)
|
||||
return
|
||||
}
|
||||
} catch (error) {
|
||||
// Fall through to browser handling.
|
||||
// Note: on Linux, system opener failures can throw here.
|
||||
console.warn("[notifications] unable to open via system opener", error)
|
||||
}
|
||||
|
||||
try {
|
||||
window.open(url, "_blank", "noopener,noreferrer")
|
||||
} catch (error) {
|
||||
console.warn("[notifications] unable to open external url", error)
|
||||
toast.error("Unable to open link")
|
||||
}
|
||||
}
|
||||
|
||||
const variantAccent: Record<
|
||||
ToastVariant,
|
||||
{
|
||||
@@ -80,14 +106,13 @@ export function showToastNotification(payload: ToastPayload): ToastHandle {
|
||||
{payload.title && <p class={`font-semibold ${accent.headline}`}>{payload.title}</p>}
|
||||
<p class={`${accent.body} ${payload.title ? "mt-1" : ""}`}>{payload.message}</p>
|
||||
{payload.action && (
|
||||
<a
|
||||
<button
|
||||
type="button"
|
||||
class="mt-3 inline-flex items-center text-xs font-semibold uppercase tracking-wide text-sky-300 hover:text-sky-200"
|
||||
href={payload.action.href}
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
onClick={() => void openExternalUrl(payload.action!.href)}
|
||||
>
|
||||
{payload.action.label}
|
||||
</a>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user