Files
fusion/packages/dashboard/app/context/ShellHostContext.tsx
Fusion 9e5bc7ca72 feat(FN-3407): normalize shell host bootstrap
Introduces a canonical shell host context and normalized bootstrap flow for the dashboard, extracting the host initialization logic into a dedicated `shell-host.ts` module with a `ShellHostContext` provider; updates `App.tsx` and `Header` to use the new context, stabilizes related tests, and documen

Fusion-Task-Id: FN-3407
2026-05-07 23:21:05 -07:00

45 lines
1.3 KiB
TypeScript

import { createContext, useContext, useMemo, type PropsWithChildren } from "react";
import { getShellHostContext, type ShellHostContext } from "../shell-host";
export interface ShellHostContextValue {
host: ShellHostContext;
isNativeShell: boolean;
kind: ShellHostContext["kind"];
mode?: "local" | "remote";
connectionId?: string;
serverUrl?: string;
canOpenConnectionManager?: boolean;
}
const DEFAULT_HOST: ShellHostContext = { kind: "browser" };
const ShellHostContextReact = createContext<ShellHostContextValue>({
host: DEFAULT_HOST,
isNativeShell: false,
kind: "browser",
});
function buildValue(host: ShellHostContext): ShellHostContextValue {
const isNativeShell = host.kind !== "browser";
return {
host,
isNativeShell,
kind: host.kind,
...(isNativeShell ? {
mode: host.mode,
connectionId: host.connectionId,
serverUrl: host.serverUrl,
canOpenConnectionManager: host.canOpenConnectionManager,
} : {}),
};
}
export function ShellHostProvider({ children }: PropsWithChildren) {
const value = useMemo(() => buildValue(getShellHostContext()), []);
return <ShellHostContextReact.Provider value={value}>{children}</ShellHostContextReact.Provider>;
}
export function useShellHostContext(): ShellHostContextValue {
return useContext(ShellHostContextReact);
}