import { Button, Icon, IconTooltip, InlineCode, LoadingIcon } from "@yaakapp-internal/ui"; import classNames from "classnames"; import { useAtomValue } from "jotai"; import type { ReactNode } from "react"; import { useRpcMutation } from "../hooks/useRpcMutation"; import { encryptingPercent } from "../lib/encrypting"; import { proxyStateAtom } from "../lib/store"; import { useCopyEnvironment, useProxySetup, useSystemProxySwitch } from "./ProxyStatus"; type StepState = "todo" | "next" | "wait" | "done" | "fail"; /** * The list's empty state until traffic arrives: turn on the system proxy, then see traffic. The * certificate is trusted at the first Decrypt, not here, as nothing needs it before. Not * dismissable and nothing remembered; the first flow replaces it. Copy environment beside it * serves someone who wants one terminal proxied and nothing system-wide. */ export function FirstRun() { const proxyState = useAtomValue(proxyStateAtom); const setup = useProxySetup(); const { systemProxy, setSystemProxy } = setup; const systemSwitch = useSystemProxySwitch(setup); const execute = useRpcMutation("execute_action"); const retry = useRpcMutation("take_over"); const copyEnvironment = useCopyEnvironment(); const running = proxyState?.state === "running"; // Changed only by the process that owns the engine, so not from here while the CLI does. const otherOwner = proxyState?.otherOwner != null; const recording = proxyState?.recording !== false; const systemSupported = systemProxy.data?.supported !== false; const systemOn = systemProxy.data?.enabled === true; const systemState: StepState = setSystemProxy.isPending ? "wait" : systemOn ? "done" : systemSwitch.failed ? "fail" : "next"; const ready = systemOn || !systemSupported; const encrypting = !running && !otherOwner ? encryptingPercent(proxyState) : null; const trafficState: StepState = encrypting != null ? "wait" : !running && !otherOwner ? "fail" : ready ? "wait" : "todo"; return (