import { Button, Icon, LoadingIcon } from "@yaakapp-internal/ui"; import classNames from "classnames"; import { useAtomValue } from "jotai"; import type { ReactNode } from "react"; import { useRpcMutation } from "../hooks/useRpcMutation"; 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: trust the certificate, turn on the system proxy, * then see traffic. 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 { caStatus, trust, 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 trusted = caStatus.data?.trusted === true; const systemSupported = systemProxy.data?.supported !== false; const systemOn = systemProxy.data?.enabled === true; const trustState: StepState = trusted ? "done" : trust.isPending ? "wait" : trust.error != null ? "fail" : "next"; const systemState: StepState = setSystemProxy.isPending ? "wait" : systemOn ? "done" : systemSwitch.failed ? "fail" : trusted ? "next" : "todo"; const ready = trusted && (systemOn || !systemSupported); const trafficState: StepState = !running && !otherOwner ? "fail" : ready ? "wait" : "todo"; return (
Set up Yaak Proxy
Three steps, once. Afterwards every app on this Mac sends its traffic here, and HTTPS reads as plain text.
trust.mutate({})} > {trustState === "fail" ? "Try again" : "Trust certificate"} ) : null } /> {systemSupported && ( setSystemProxy.mutate({ enabled: true })} > {systemState === "fail" ? "Try again" : "Turn on"} ) : null } /> )} retry.mutate({})} > Retry ) : !recording && running ? ( ) : null } />
Only need one terminal or one app? Copy the environment instead.
); } function Step({ n, state, title, description, action, }: { n: number; state: StepState; title: string; description: ReactNode; action: ReactNode; }) { return (
{title}
{description}
{action}
); } function StepMark({ n, state }: { n: number; state: StepState }) { const base = "w-[1.4rem] h-[1.4rem] rounded-full grid place-items-center text-xs"; switch (state) { case "done": return ( ); case "fail": return ( ); case "wait": return ( ); case "next": return {n}; case "todo": return {n}; } }