import { useMemo, useState } from "react"; import type { FusionShellApi, ShellConnectionProfile, ShellConnectionState } from "../types/native-shell"; import "./NativeShellConnectionManager.css"; interface NativeShellConnectionManagerProps { open: boolean; shellApi: FusionShellApi; shellState: ShellConnectionState; onClose: () => void; } export function NativeShellConnectionManager({ open, shellApi, shellState, onClose }: NativeShellConnectionManagerProps) { const activeProfile = useMemo( () => shellState.profiles.find((profile) => profile.id === shellState.activeProfileId) ?? null, [shellState.activeProfileId, shellState.profiles], ); const [draft, setDraft] = useState>({}); const [error, setError] = useState(null); if (!open) return null; const workingName = draft.name ?? activeProfile?.name ?? ""; const workingUrl = draft.serverUrl ?? activeProfile?.serverUrl ?? ""; const workingToken = draft.authToken ?? activeProfile?.authToken ?? ""; const saveCurrent = async () => { setError(null); try { // Early validation for user feedback before bridge persistence rejects. const parsed = new URL(workingUrl.trim()); if (!/^https?:$/.test(parsed.protocol)) { throw new Error("Server URL must use http or https"); } const saved = await shellApi.saveProfile({ id: activeProfile?.id, name: workingName || "Remote Server", serverUrl: workingUrl, authToken: workingToken || null, }); await shellApi.setActiveProfile(saved.id); setDraft({}); } catch (nextError) { setError((nextError as Error).message); } }; return (

Connection Manager

{shellState.host === "desktop-shell" && (
)}
{shellState.profiles.map((profile) => (
{profile.name}
{profile.serverUrl}
))}
setDraft((value) => ({ ...value, name: event.target.value }))} /> setDraft((value) => ({ ...value, serverUrl: event.target.value }))} /> setDraft((value) => ({ ...value, authToken: event.target.value }))} /> {error &&

{error}

}
); }