import { patchModel, settingsAtom } from "@yaakapp-internal/models"; import type { ProxySetting } from "@yaakapp-internal/models"; import { Heading, InlineCode, VStack } from "@yaakapp-internal/ui"; import { useAtomValue } from "jotai"; import { SettingRowBoolean, SettingRowSelect, SettingRowText, SettingsList, SettingsSection, } from "../core/SettingRow"; export function SettingsProxy() { const settings = useAtomValue(settingsAtom); const proxy = enabledProxyOrDefault(settings.proxy); const patchProxy = async (patch: Partial) => { await patchModel(settings, { proxy: { ...proxy, ...patch, auth: Object.hasOwn(patch, "auth") ? (patch.auth ?? null) : proxy.auth, }, }); }; return (
Proxy

Configure a proxy server for HTTP requests. Useful for corporate firewalls, debugging traffic, or routing through specific infrastructure.

{ if (v === "automatic") { await patchModel(settings, { proxy: undefined }); } else if (v === "enabled") { await patchModel(settings, { proxy }); } else { await patchModel(settings, { proxy: { type: "disabled" } }); } }} options={[ { label: "Automatic proxy detection", value: "automatic" }, { label: "Custom proxy configuration", value: "enabled" }, { label: "No proxy", value: "disabled" }, ]} selectClassName="!w-64" /> {settings.proxy?.type === "enabled" && ( <> patchProxy({ disabled: !enabled })} /> Proxy for http:// traffic } description="Proxy host used for unencrypted HTTP traffic." value={settings.proxy.http} placeholder="localhost:9090" onChange={(http) => patchProxy({ http })} /> Proxy for https:// traffic } description="Proxy host used for HTTPS traffic." value={settings.proxy.https} placeholder="localhost:9090" onChange={(https) => patchProxy({ https })} /> patchProxy({ bypass })} /> patchProxy({ auth: enabled ? { user: "", password: "" } : null }) } /> {settings.proxy.auth != null && ( <> patchProxy({ auth: { user, password: settings.proxy?.type === "enabled" ? (settings.proxy.auth?.password ?? "") : "", }, }) } /> patchProxy({ auth: { user: settings.proxy?.type === "enabled" ? (settings.proxy.auth?.user ?? "") : "", password, }, }) } /> )} )}
); } type EnabledProxySetting = Extract; function enabledProxyOrDefault(proxy: ProxySetting | null): EnabledProxySetting { if (proxy?.type === "enabled") return proxy; return { disabled: false, type: "enabled", http: "", https: "", auth: { user: "", password: "" }, bypass: "", }; }