// Detects whether the Tauri runtime is present in the current window.
//
// In Tauri v2 the bootstrap script injects `window.__TAURI_INTERNALS__`
// before the page script runs, and also sets `window.isTauri = true` as
// a convenience marker. Either is sufficient evidence we are inside a
// Tauri webview.
//
// In a plain browser (vite preview, `npm run dev` outside `tauri dev`)
// neither global is set, so `hasTauriRuntime()` returns false. Callers
// use this to gate `invoke()` calls and fall back to localStorage-only
// behaviour for browser-preview mode.

export function hasTauriRuntime() {
  if (typeof window === "undefined") return false;
  if (window.__TAURI_INTERNALS__) return true;
  if (window.isTauri === true) return true;
  return false;
}
