diff --git a/UPDATELOG.md b/UPDATELOG.md index d1d10b10..38a39da4 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -48,6 +48,7 @@ - 卸载服务的按钮 - 添加了Zashboard的一键跳转URL - 使用操作系统默认的窗口管理器 + - 切换、升级、重启内核的状态管理 #### 优化了: - 系统代理 Bypass 设置 diff --git a/src/components/setting/mods/clash-core-viewer.tsx b/src/components/setting/mods/clash-core-viewer.tsx index 4ba9137b..a7f4fc02 100644 --- a/src/components/setting/mods/clash-core-viewer.tsx +++ b/src/components/setting/mods/clash-core-viewer.tsx @@ -11,8 +11,8 @@ import { } from "@mui/icons-material"; import { Box, - Button, Chip, + CircularProgress, List, ListItemButton, ListItemText, @@ -33,6 +33,8 @@ export const ClashCoreViewer = forwardRef((props, ref) => { const [open, setOpen] = useState(false); const [upgrading, setUpgrading] = useState(false); + const [restarting, setRestarting] = useState(false); + const [changingCore, setChangingCore] = useState(null); useImperativeHandle(ref, () => ({ open: () => setOpen(true), @@ -45,11 +47,13 @@ export const ClashCoreViewer = forwardRef((props, ref) => { if (core === clash_core) return; try { + setChangingCore(core); closeAllConnections(); const errorMsg = await changeClashCore(core); if (errorMsg) { showNotice('error', errorMsg); + setChangingCore(null); return; } @@ -57,17 +61,22 @@ export const ClashCoreViewer = forwardRef((props, ref) => { setTimeout(() => { mutate("getClashConfig"); mutate("getVersion"); + setChangingCore(null); }, 500); } catch (err: any) { + setChangingCore(null); showNotice('error', err.message || err.toString()); } }); const onRestart = useLockFn(async () => { try { + setRestarting(true); await restartCore(); showNotice('success', t(`Clash Core Restarted`)); + setRestarting(false); } catch (err: any) { + setRestarting(false); showNotice('error', err.message || err.toString()); } }); @@ -97,19 +106,23 @@ export const ClashCoreViewer = forwardRef((props, ref) => { startIcon={} loadingPosition="start" loading={upgrading} + disabled={restarting || changingCore !== null} sx={{ marginRight: "8px" }} onClick={onUpgrade} > {t("Upgrade")} - + } @@ -132,9 +145,14 @@ export const ClashCoreViewer = forwardRef((props, ref) => { key={each.core} selected={each.core === clash_core} onClick={() => onCoreChange(each.core)} + disabled={changingCore !== null || restarting || upgrading} > - + {changingCore === each.core ? ( + + ) : ( + + )} ))}