import useSWR from "swr"; import { useState } from "react"; import { useLockFn } from "ahooks"; import { useTranslation } from "react-i18next"; import { Button, Dialog, DialogActions, DialogContent, DialogTitle, List, ListItem, ListItemText, TextField, } from "@mui/material"; import { getClashInfo, patchClashConfig } from "@/services/cmds"; import { ModalHandler } from "@/hooks/use-modal-handler"; import { getAxios } from "@/services/api"; import Notice from "@/components/base/base-notice"; interface Props { handler: ModalHandler; } const ControllerViewer = ({ handler }: Props) => { const { t } = useTranslation(); const [open, setOpen] = useState(false); const { data: clashInfo, mutate } = useSWR("getClashInfo", getClashInfo); const [controller, setController] = useState(clashInfo?.server || ""); const [secret, setSecret] = useState(clashInfo?.secret || ""); if (handler) { handler.current = { open: () => { setOpen(true); setController(clashInfo?.server || ""); setSecret(clashInfo?.secret || ""); }, close: () => setOpen(false), }; } const onSave = useLockFn(async () => { try { await patchClashConfig({ "external-controller": controller, secret }); mutate(); // 刷新接口 getAxios(true); Notice.success("Change Clash Config successfully!", 1000); setOpen(false); } catch (err) { console.log(err); } }); return ( setOpen(false)}> {t("Clash Port")} setController(e.target.value)} /> setSecret(e.target.value)} /> ); }; export default ControllerViewer;