/** * 代理模式切换开关组件 * * 放置在主界面头部,用于一键启用/关闭代理模式 * 启用时自动接管 Live 配置,关闭时恢复原始配置 */ import { Radio, Loader2 } from "lucide-react"; import { Switch } from "@/components/ui/switch"; import { useProxyStatus } from "@/hooks/useProxyStatus"; import { cn } from "@/lib/utils"; interface ProxyToggleProps { className?: string; } export function ProxyToggle({ className }: ProxyToggleProps) { const { isRunning, isTakeoverActive, startWithTakeover, stopWithRestore, isPending, status, } = useProxyStatus(); const handleToggle = async (checked: boolean) => { if (checked) { await startWithTakeover(); } else { await stopWithRestore(); } }; const isActive = isRunning && isTakeoverActive; const tooltipText = isActive ? `代理模式运行中 - ${status?.address}:${status?.port}\n切换供应商为热切换` : "开启代理模式\n启用后自动接管 Live 配置"; return (