Open History to see the last commit
1import { DownloadIcon } from "lucide-react";
2import { msg, T, useGT, useMessages, Var } from "gt-react";
3import { useSyncExternalStore } from "react";
4import type { RelayClientInstallProgressStage } from "@t3tools/contracts";
5
6import {
7 completeRelayClientInstallDialogClose,
8 readRelayClientInstallDialogState,
9 respondToRelayClientInstallConfirmation,
10 subscribeRelayClientInstallDialog,
11} from "../../cloud/relayClientInstallDialog";
12import { Button } from "../ui/button";
13import {
14 Dialog,
15 DialogDescription,
16 DialogAction,
17 DialogFooter,
18 DialogHeader,
19 DialogPanel,
20 DialogPopup,
21 DialogTitle,
22} from "../ui/dialog";
23const installSteps: ReadonlyArray<{
24 readonly stage: RelayClientInstallProgressStage;
25 readonly label: string;
26}> = [
27 { stage: "checking", label: msg("Checking current installation") },
28 { stage: "waiting_for_lock", label: msg("Waiting for installer") },
29 { stage: "downloading", label: msg("Downloading relay client") },
30 { stage: "verifying", label: msg("Verifying download") },
31 { stage: "installing", label: msg("Installing relay client") },
32 { stage: "validating", label: msg("Validating executable") },
33 { stage: "activating", label: msg("Activating installation") },
34];
35
36export function RelayClientInstallDialog() {
37 const state = useSyncExternalStore(
38 subscribeRelayClientInstallDialog,
39 readRelayClientInstallDialogState,
40 readRelayClientInstallDialogState,
41 );
42 const gt = useGT();
43 const m = useMessages();
44 const view = state.status === "closing" ? state.view : state;
45 const isConfirming = view.status === "confirming";
46 const isInstalling = view.status === "installing";
47 const activeStepIndex = isInstalling
48 ? installSteps.findIndex(({ stage }) => stage === view.stage)
49 : -1;
50 const activeStep = installSteps[activeStepIndex];
51
52 return (
53 <Dialog
54 open={state.status === "confirming" || state.status === "installing"}
55 onOpenChange={(open) => {
56 if (!open && isConfirming) {
57 respondToRelayClientInstallConfirmation(false);
58 }
59 }}
60 onOpenChangeComplete={(open) => {
61 if (!open) {
62 completeRelayClientInstallDialogClose();
63 }
64 }}
65 >
66 <DialogPopup className="max-w-md" showCloseButton={isConfirming}>
67 <DialogHeader>
68 <div className="flex size-9 items-center justify-center rounded-lg border border-border/70 bg-muted/60">
69 <DownloadIcon aria-hidden className="size-4.5 text-muted-foreground" />
70 </div>
71 <DialogTitle>
72 {isInstalling ? gt`Installing relay client` : gt`Install relay client?`}
73 </DialogTitle>
74 <DialogDescription>
75 {isInstalling
76 ? gt`T3 Code is preparing this environment for secure access through T3 Connect.`
77 : gt`T3 Code needs the relay client to make this environment available through T3 Connect.`}
78 </DialogDescription>
79 </DialogHeader>
80 <DialogPanel scrollFade={false}>
81 {isInstalling ? (
82 <div className="space-y-2.5">
83 <div className="flex items-center justify-between gap-3 text-sm">
84 <p aria-live="polite" className="font-medium text-foreground">
85 {activeStep ? m(activeStep.label) : null}
86 </p>
87 <p className="shrink-0 tabular-nums text-muted-foreground">
88 {gt`${{ step: activeStepIndex + 1 }} of ${{ total: installSteps.length }}`}
89 </p>
90 </div>
91 <progress
92 aria-label={gt`Relay client installation progress`}
93 className="h-2 w-full appearance-none overflow-hidden rounded-full bg-muted [&::-moz-progress-bar]:rounded-full [&::-moz-progress-bar]:bg-primary [&::-webkit-progress-bar]:rounded-full [&::-webkit-progress-bar]:bg-muted [&::-webkit-progress-value]:rounded-full [&::-webkit-progress-value]:bg-primary"
94 max={installSteps.length}
95 value={activeStepIndex + 1}
96 />
97 <p className="text-xs leading-relaxed text-muted-foreground">
98 <T>Keep T3 Code open while the relay client is installed.</T>
99 </p>
100 </div>
101 ) : (
102 <div className="rounded-xl border border-border/70 bg-muted/35 p-3">
103 <p className="text-sm font-medium text-foreground">
104 <T>Managed relay client</T>
105 </p>
106 <p className="mt-1 text-sm leading-relaxed text-muted-foreground">
107 <T>
108 T3 Code will download and install version{" "}
109 <Var>{view.status === "confirming" ? view.version : ""}</Var> locally.
110 </T>
111 </p>
112 </div>
113 )}
114 </DialogPanel>
115 {isConfirming ? (
116 <DialogFooter>
117 <Button
118 variant="outline"
119 onClick={() => respondToRelayClientInstallConfirmation(false)}
120 >
121 <T>Cancel</T>
122 </Button>
123 <DialogAction onClick={() => respondToRelayClientInstallConfirmation(true)}>
124 <T>Download and install</T>
125 </DialogAction>
126 </DialogFooter>
127 ) : null}
128 </DialogPopup>
129 </Dialog>
130 );
131}