import { LocalStorage } from "@raycast/api"; import { links } from "@appy/api"; export type Browser = { name: string; path: string; bundleId: string }; /** How a link opens: always in the primary browser, or with a choice each time. */ export type Mode = "primary" | "ask"; /** Hosts that always open in their own app when it is installed (like Velja's built-in rules). */ export const APP_RULES: { name: string; host: RegExp; app: string }[] = [ { name: "Zoom", host: /(^|\.)zoom\.us$/, app: "/Applications/zoom.us.app" }, { name: "Figma", host: /(^|\.)figma\.com$/, app: "/Applications/Figma.app" }, { name: "Slack", host: /(^|\.)slack\.com$/, app: "/Applications/Slack.app" }, ]; export async function primary(): Promise { return (await LocalStorage.getItem("primary")) || undefined; } export async function mode(): Promise { return (await LocalStorage.getItem("mode")) === "ask" ? "ask" : "primary"; } export async function browsers(): Promise { return (await links.browsers()) as Browser[]; } /** The primary browser, else Safari, else the first one found. */ export async function chosen(all?: Browser[]): Promise { const list = all ?? (await browsers()); return (await primary()) || list.find((b) => b.bundleId === "com.apple.Safari")?.path || list[0]?.path; } export const isLink = (text: string) => /^https?:\/\/\S+$/i.test(text.trim());