// Thin wrappers around Tauri APIs with browser fallbacks, so `npm run dev` // in a plain browser stays usable for UI work. export const inTauri = typeof window !== "undefined" && "__TAURI_INTERNALS__" in window; export async function copyText(text: string): Promise { if (inTauri) { const { writeText } = await import("@tauri-apps/plugin-clipboard-manager"); await writeText(text); } else { await navigator.clipboard.writeText(text); } } export async function hideWindow(): Promise { if (!inTauri) return; const { invoke } = await import("@tauri-apps/api/core"); await invoke("hide_window"); } export async function getHotkey(): Promise { if (!inTauri) return "ctrl+shift+k"; const { invoke } = await import("@tauri-apps/api/core"); return invoke("get_hotkey"); } export async function setHotkey(hotkey: string): Promise { if (!inTauri) return; const { invoke } = await import("@tauri-apps/api/core"); await invoke("set_hotkey", { hotkey }); } type StoreValue = string | number | boolean; export async function storeGet(key: string): Promise { if (inTauri) { const { load } = await import("@tauri-apps/plugin-store"); const store = await load("settings.json"); return (await store.get(key)) ?? undefined; } const raw = localStorage.getItem(key); return raw === null ? undefined : (JSON.parse(raw) as T); } export async function storeSet(key: string, value: StoreValue): Promise { if (inTauri) { const { load } = await import("@tauri-apps/plugin-store"); const store = await load("settings.json"); await store.set(key, value); await store.save(); } else { localStorage.setItem(key, JSON.stringify(value)); } } export async function getAutostart(): Promise { if (!inTauri) return false; const { isEnabled } = await import("@tauri-apps/plugin-autostart"); return isEnabled(); } export async function setAutostart(enabled: boolean): Promise { if (!inTauri) return; const { enable, disable } = await import("@tauri-apps/plugin-autostart"); if (enabled) await enable(); else await disable(); }