import useSWR, { mutate } from "swr"; import { useRef } from "react"; import { useTranslation } from "react-i18next"; import { SettingsRounded, PlayArrowRounded, PauseRounded, } from "@mui/icons-material"; import { useVerge } from "@/hooks/use-verge"; import { DialogRef, Notice, Switch } from "@/components/base"; import { SettingList, SettingItem } from "./mods/setting-comp"; import { GuardState } from "./mods/guard-state"; import { SysproxyViewer } from "./mods/sysproxy-viewer"; import { TunViewer } from "./mods/tun-viewer"; import { TooltipIcon } from "@/components/base/base-tooltip-icon"; import { getSystemProxy, getAutotemProxy } from "@/services/cmds"; interface Props { onError?: (err: Error) => void; } const SettingSystem = ({ onError }: Props) => { const { t } = useTranslation(); const { verge, mutateVerge, patchVerge } = useVerge(); const { data: sysproxy } = useSWR("getSystemProxy", getSystemProxy); const { data: autoproxy } = useSWR("getAutotemProxy", getAutotemProxy); const sysproxyRef = useRef(null); const tunRef = useRef(null); const { enable_tun_mode, enable_auto_launch, enable_silent_start, enable_system_proxy, proxy_auto_config, } = verge ?? {}; const isProxyEnabled = proxy_auto_config ? autoproxy?.enable : sysproxy?.enable; const onSwitchFormat = (_e: any, value: boolean) => value; const onChangeData = (patch: Partial) => { mutateVerge({ ...verge, ...patch }, false); }; const updateProxyStatus = async () => { // 等待一小段时间让系统代理状态变化 await new Promise((resolve) => setTimeout(resolve, 100)); await mutate("getSystemProxy"); await mutate("getAutotemProxy"); }; return ( tunRef.current?.open()} /> } > { onChangeData({ enable_tun_mode: e }); }} onGuard={(e) => { return patchVerge({ enable_tun_mode: e }); }} > sysproxyRef.current?.open()} /> {isProxyEnabled ? ( ) : ( )} } > onChangeData({ enable_system_proxy: e })} onGuard={async (e) => { await patchVerge({ enable_system_proxy: e }); await updateProxyStatus(); }} > onChangeData({ enable_auto_launch: e })} onGuard={(e) => patchVerge({ enable_auto_launch: e })} > } > onChangeData({ enable_silent_start: e })} onGuard={(e) => patchVerge({ enable_silent_start: e })} > ); }; export default SettingSystem;