import { DownloadIcon } from "lucide-react"; import { useSyncExternalStore } from "react"; import type { RelayClientInstallProgressStage } from "@t3tools/contracts"; import { completeRelayClientInstallDialogClose, readRelayClientInstallDialogState, respondToRelayClientInstallConfirmation, subscribeRelayClientInstallDialog, } from "../../cloud/relayClientInstallDialog"; import { Button } from "../ui/button"; import { Dialog, DialogDescription, DialogFooter, DialogHeader, DialogPanel, DialogPopup, DialogTitle, } from "../ui/dialog"; const installSteps: ReadonlyArray<{ readonly stage: RelayClientInstallProgressStage; readonly label: string; }> = [ { stage: "checking", label: "Checking current installation" }, { stage: "waiting_for_lock", label: "Waiting for installer" }, { stage: "downloading", label: "Downloading relay client" }, { stage: "verifying", label: "Verifying download" }, { stage: "installing", label: "Installing relay client" }, { stage: "validating", label: "Validating executable" }, { stage: "activating", label: "Activating installation" }, ]; export function RelayClientInstallDialog() { const state = useSyncExternalStore( subscribeRelayClientInstallDialog, readRelayClientInstallDialogState, readRelayClientInstallDialogState, ); const view = state.status === "closing" ? state.view : state; const isConfirming = view.status === "confirming"; const isInstalling = view.status === "installing"; const activeStepIndex = isInstalling ? installSteps.findIndex(({ stage }) => stage === view.stage) : -1; const activeStep = installSteps[activeStepIndex]; return ( { if (!open && isConfirming) { respondToRelayClientInstallConfirmation(false); } }} onOpenChangeComplete={(open) => { if (!open) { completeRelayClientInstallDialogClose(); } }} >
{isInstalling ? "Installing relay client" : "Install relay client?"} {isInstalling ? "T3 Code is preparing this environment for secure access through T3 Connect." : "T3 Code needs the relay client to make this environment available through T3 Connect."}
{isInstalling ? (

{activeStep?.label}

{activeStepIndex + 1} of {installSteps.length}

Keep T3 Code open while the relay client is installed.

) : (

Managed relay client

T3 Code will download and install version{" "} {view.status === "confirming" ? view.version : ""} locally.

)}
{isConfirming ? ( ) : null}
); }