import useSWR, { useSWRConfig } from "swr"; import { List, ListItemText, ListSubheader, Switch } from "@mui/material"; import { getVergeConfig, patchVergeConfig, setSysProxy, } from "../services/cmds"; import { CmdType } from "../services/types"; import GuardState from "./guard-state"; import SettingItem from "./setting-item"; import PaletteSwitch from "./palette-switch"; interface Props { onError?: (err: Error) => void; } const SettingVerge = ({ onError }: Props) => { const { mutate } = useSWRConfig(); const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig); const { theme_mode: mode = "light", enable_self_startup: startup = false, enable_system_proxy: proxy = false, } = vergeConfig ?? {}; const onSwitchFormat = (_e: any, value: boolean) => value; const onChangeData = (patch: Partial) => { mutate("getVergeConfig", { ...vergeConfig, ...patch }, false); }; return ( 通用设置 onChangeData({ theme_mode: e ? "dark" : "light" })} onGuard={async (c) => { await patchVergeConfig({ theme_mode: c ? "dark" : "light" }); }} > onChangeData({ enable_self_startup: e })} onGuard={async (e) => { await patchVergeConfig({ enable_self_startup: e }); }} > onChangeData({ enable_system_proxy: e })} onGuard={async (e) => { await setSysProxy(e); await patchVergeConfig({ enable_system_proxy: e }); }} > ); }; export default SettingVerge;