diff --git a/UPDATELOG.md b/UPDATELOG.md index f7383d1f..dd62f8de 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -33,6 +33,7 @@ - 选择按延迟排序时每次延迟测试自动刷新节点顺序 - 配置重载失败时自动重启核心 - 启用 TUN 前等待服务就绪 +- 卸载 TUN 时会先关闭 ### 🐞 修复问题 diff --git a/src/components/shared/ProxyControlSwitches.tsx b/src/components/shared/ProxyControlSwitches.tsx index c775f91e..ccf3ec7b 100644 --- a/src/components/shared/ProxyControlSwitches.tsx +++ b/src/components/shared/ProxyControlSwitches.tsx @@ -1,14 +1,14 @@ import { - SettingsRounded, - PlayCircleOutlineRounded, - PauseCircleOutlineRounded, BuildRounded, DeleteForeverRounded, + PauseCircleOutlineRounded, + PlayCircleOutlineRounded, + SettingsRounded, WarningRounded, } from "@mui/icons-material"; import { Box, Typography, alpha, useTheme } from "@mui/material"; import { useLockFn } from "ahooks"; -import React, { useRef, useCallback } from "react"; +import React, { useCallback, useRef } from "react"; import { useTranslation } from "react-i18next"; import { DialogRef, Switch } from "@/components/base"; @@ -122,6 +122,7 @@ const ProxyControlSwitches = ({ isTunModeAvailable, mutateRunningMode, mutateServiceOk, + mutateTunModeAvailable, } = useSystemState(); const sysproxyRef = useRef(null); @@ -149,6 +150,7 @@ const ProxyControlSwitches = ({ await installServiceAndRestartCore(); await mutateRunningMode(); await mutateServiceOk(); + await mutateTunModeAvailable(); } catch (err) { showNotice("error", (err as Error).message || String(err)); } @@ -156,9 +158,11 @@ const ProxyControlSwitches = ({ const onUninstallService = useLockFn(async () => { try { + await handleTunToggle(false); await uninstallServiceAndRestartCore(); await mutateRunningMode(); await mutateServiceOk(); + await mutateTunModeAvailable(); } catch (err) { showNotice("error", (err as Error).message || String(err)); } @@ -184,13 +188,13 @@ const ProxyControlSwitches = ({ {isTunMode && ( tunRef.current?.open()} onToggle={handleTunToggle} onError={onError} disabled={!isTunModeAvailable} - highlight={!!enable_tun_mode} + highlight={enable_tun_mode || false} extraIcons={ <> {!isTunModeAvailable && ( @@ -200,7 +204,7 @@ const ProxyControlSwitches = ({ sx={{ color: "warning.main", ml: 1 }} /> )} - {!isServiceMode ? ( + {!isTunModeAvailable && ( - ) : ( + )} + {isServiceMode && ( isAdminMode || isServiceOk, + { + suspense: false, + revalidateOnFocus: false, + }, + ); return { runningMode, @@ -56,9 +64,10 @@ export function useSystemState() { isSidecarMode, isServiceMode, isServiceOk, - isTunModeAvailable: isTunModeAvailable, + isTunModeAvailable, mutateRunningMode, mutateServiceOk, + mutateTunModeAvailable, isLoading, }; }