import useSWR, { useSWRConfig } from "swr"; import { List, ListItemText, ListSubheader, TextField, Switch, Select, MenuItem, } from "@mui/material"; import { ConfigType, getClashConfig, updateConfigs } from "../services/common"; import { patchClashConfig } from "../services/command"; import GuardState from "./guard-state"; import SettingItem from "./setting-item"; interface Props { onError?: (err: Error) => void; } const SettingClash = ({ onError }: Props) => { const { mutate } = useSWRConfig(); const { data: clashConfig } = useSWR("getClashConfig", getClashConfig); const { ipv6 = false, "allow-lan": allowLan = false, "log-level": logLevel = "silent", "mixed-port": mixedPort = 7890, } = clashConfig ?? {}; const onSwitchFormat = (_e: any, value: boolean) => value; const onChangeData = (patch: Partial) => { mutate("getClashConfig", { ...clashConfig, ...patch }, false); }; const onUpdateData = async (patch: Partial) => { await updateConfigs(patch); await patchClashConfig(patch); }; return ( Clash设置 onChangeData({ "allow-lan": e })} onGuard={(e) => onUpdateData({ "allow-lan": e })} > onChangeData({ ipv6: e })} onGuard={(e) => onUpdateData({ ipv6: e })} > e.target.value} onChange={(e) => onChangeData({ "log-level": e })} onGuard={(e) => onUpdateData({ "log-level": e })} > ); }; export default SettingClash;