import { LaunchType, launchCommand, open } from "@raycast/api"; import { existsSync } from "fs"; import { APP_RULES, chosen, mode } from "./shared"; // Appy runs this for each link while it is the default browser: a rule's app when one matches, else a choice in the // launcher ("Ask Every Time"), else the primary browser. export default async function Command(props: { launchContext?: { url?: string } }) { const url = props.launchContext?.url; if (!url) return; let host = ""; try { host = new URL(url).hostname; } catch { return; } const rule = APP_RULES.find((r) => r.host.test(host) && existsSync(r.app)); if (rule) return open(url, rule.app); if ((await mode()) === "ask") return launchCommand({ name: "choose", type: LaunchType.UserInitiated, context: { url } }); await open(url, await chosen()); }