Build overlay frontend: tabs, search, param forms, copy-to-clipboard
Quick Cheats, full command DB with category/source filters, item/perk/ buff/skill databases with fill-in parameters and per-flavor command variants, settings tab with hotkey recorder, opacity, flavor, autostart. Dark HUD theme on a transparent frameless window. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
// 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<void> {
|
||||
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<void> {
|
||||
if (!inTauri) return;
|
||||
const { invoke } = await import("@tauri-apps/api/core");
|
||||
await invoke("hide_window");
|
||||
}
|
||||
|
||||
export async function getHotkey(): Promise<string> {
|
||||
if (!inTauri) return "ctrl+shift+k";
|
||||
const { invoke } = await import("@tauri-apps/api/core");
|
||||
return invoke<string>("get_hotkey");
|
||||
}
|
||||
|
||||
export async function setHotkey(hotkey: string): Promise<void> {
|
||||
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<T extends StoreValue>(key: string): Promise<T | undefined> {
|
||||
if (inTauri) {
|
||||
const { load } = await import("@tauri-apps/plugin-store");
|
||||
const store = await load("settings.json");
|
||||
return (await store.get<T>(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<void> {
|
||||
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<boolean> {
|
||||
if (!inTauri) return false;
|
||||
const { isEnabled } = await import("@tauri-apps/plugin-autostart");
|
||||
return isEnabled();
|
||||
}
|
||||
|
||||
export async function setAutostart(enabled: boolean): Promise<void> {
|
||||
if (!inTauri) return;
|
||||
const { enable, disable } = await import("@tauri-apps/plugin-autostart");
|
||||
if (enabled) await enable();
|
||||
else await disable();
|
||||
}
|
||||
Reference in New Issue
Block a user