import { Action, ActionPanel, Clipboard, Icon, List, closeMainWindow, open } from "@raycast/api"; import { useEffect, useState } from "react"; import { Browser, browsers, chosen, isLink } from "./shared"; // The Velja-style chooser: the link being opened (or the one on the clipboard) and every browser, primary first. export default function Choose(props: { launchContext?: { url?: string } }) { const [url, setURL] = useState(props.launchContext?.url); const [list, setList] = useState(); const [first, setFirst] = useState(); useEffect(() => { (async () => { if (!url) { const text = (await Clipboard.readText())?.trim() || ""; if (isLink(text)) setURL(text); } const all = await browsers(); const main = await chosen(all); setFirst(main); setList([...all.filter((b) => b.path === main), ...all.filter((b) => b.path !== main)]); })(); }, []); let host = ""; try { host = url ? new URL(url).hostname.replace(/^www\./, "") : ""; } catch {} async function go(path: string) { if (!url) return; await closeMainWindow(); await open(url, path); } return ( {!url ? ( ) : ( {(list || []).map((b) => ( go(b.path)} /> } /> ))} )} ); }