import { invoke } from "@tauri-apps/api/core"; import { useEffect, useState } from "react"; import { ShellFamily } from "./commandAssembly"; // Cache the (constant, per-session) lookup so every CommandBuilder mount shares // one invoke. PowerShell needs its own quoting; bash/zsh/fish are all POSIX. let cached: Promise | undefined; function loadShellFamily(): Promise { if (!cached) { cached = invoke("get_shell_info") .then((s): ShellFamily => (s === "powershell" ? "powershell" : "posix")) // Not inside Tauri (bare `pnpm dev`) or command failed: POSIX is the safe // default (identical to PowerShell for values without embedded quotes). .catch((): ShellFamily => "posix"); } return cached; } /** * The shell family the app spawns, used to quote assembled commands. Resolved * from the backend's `get_shell_info` (the shell `async_create_shell` actually * launched), defaulting to "posix" until it loads. */ export function useShellFamily(): ShellFamily { const [shell, setShell] = useState("posix"); useEffect(() => { let active = true; loadShellFamily().then((family) => { if (active) setShell(family); }); return () => { active = false; }; }, []); return shell; }