fix: unify TUN status detection logic
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
- 修复日志等级设置保存问题
|
||||
- 修复日志等级异常过滤
|
||||
- 修复偶发性启动卡死问题
|
||||
- 修复首页虚拟网卡开关在管理模式下的状态问题
|
||||
|
||||
### 🔧 技术改进
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
useTheme,
|
||||
Fade,
|
||||
} from "@mui/material";
|
||||
import { useState, useMemo, memo, FC, useEffect } from "react";
|
||||
import { useState, useMemo, memo, FC } from "react";
|
||||
import ProxyControlSwitches from "@/components/shared/ProxyControlSwitches";
|
||||
import {
|
||||
ComputerRounded,
|
||||
@@ -21,8 +21,6 @@ import { useVerge } from "@/hooks/use-verge";
|
||||
import { useSystemState } from "@/hooks/use-system-state";
|
||||
import { useSystemProxyState } from "@/hooks/use-system-proxy-state";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
import { getRunningMode } from "@/services/cmds";
|
||||
import { mutate } from "swr";
|
||||
|
||||
const LOCAL_STORAGE_TAB_KEY = "clash-verge-proxy-active-tab";
|
||||
|
||||
@@ -142,30 +140,13 @@ export const ProxyTunCard: FC = () => {
|
||||
() => localStorage.getItem(LOCAL_STORAGE_TAB_KEY) || "system",
|
||||
);
|
||||
|
||||
const [localServiceOk, setLocalServiceOk] = useState(false);
|
||||
|
||||
const { verge } = useVerge();
|
||||
const { isAdminMode } = useSystemState();
|
||||
const { isAdminMode, isServiceMode } = useSystemState();
|
||||
const { actualState: systemProxyActualState } = useSystemProxyState();
|
||||
|
||||
const { enable_tun_mode } = verge ?? {};
|
||||
|
||||
const updateLocalStatus = async () => {
|
||||
try {
|
||||
const runningMode = await getRunningMode();
|
||||
const serviceStatus = runningMode === "Service";
|
||||
setLocalServiceOk(serviceStatus);
|
||||
mutate("isServiceAvailable", serviceStatus, false);
|
||||
} catch (error) {
|
||||
console.error("更新TUN状态失败:", error);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
updateLocalStatus();
|
||||
}, []);
|
||||
|
||||
const isTunAvailable = localServiceOk || isAdminMode;
|
||||
const isTunAvailable = isServiceMode || isAdminMode;
|
||||
|
||||
const handleError = (err: Error) => {
|
||||
showNotice("error", err.message || err.toString());
|
||||
@@ -174,9 +155,6 @@ export const ProxyTunCard: FC = () => {
|
||||
const handleTabChange = (tab: string) => {
|
||||
setActiveTab(tab);
|
||||
localStorage.setItem(LOCAL_STORAGE_TAB_KEY, tab);
|
||||
if (tab === "tun") {
|
||||
updateLocalStatus();
|
||||
}
|
||||
};
|
||||
|
||||
const tabDescription = useMemo(() => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useRef } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import useSWR from "swr";
|
||||
import {
|
||||
SettingsRounded,
|
||||
PlayCircleOutlineRounded,
|
||||
@@ -21,7 +20,7 @@ import { SysproxyViewer } from "@/components/setting/mods/sysproxy-viewer";
|
||||
import { TunViewer } from "@/components/setting/mods/tun-viewer";
|
||||
import { useVerge } from "@/hooks/use-verge";
|
||||
import { useSystemProxyState } from "@/hooks/use-system-proxy-state";
|
||||
import { getRunningMode } from "@/services/cmds";
|
||||
import { useSystemState } from "@/hooks/use-system-state";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
import { useServiceInstaller } from "@/hooks/useServiceInstaller";
|
||||
|
||||
@@ -43,10 +42,9 @@ const ProxyControlSwitches = ({ label, onError }: ProxySwitchProps) => {
|
||||
const { actualState: systemProxyActualState, toggleSystemProxy } =
|
||||
useSystemProxyState();
|
||||
|
||||
const { data: runningMode } = useSWR("getRunningMode", getRunningMode);
|
||||
const { isAdminMode, isServiceMode } = useSystemState();
|
||||
|
||||
// 是否以sidecar模式运行
|
||||
const isSidecarMode = runningMode === "Sidecar";
|
||||
const isTunAvailable = isServiceMode || isAdminMode;
|
||||
|
||||
const sysproxyRef = useRef<DialogRef>(null);
|
||||
const tunRef = useRef<DialogRef>(null);
|
||||
@@ -161,7 +159,7 @@ const ProxyControlSwitches = ({ label, onError }: ProxySwitchProps) => {
|
||||
bgcolor: enable_tun_mode
|
||||
? alpha(theme.palette.success.main, 0.07)
|
||||
: "transparent",
|
||||
opacity: isSidecarMode ? 0.6 : 1,
|
||||
opacity: !isTunAvailable ? 0.6 : 1,
|
||||
transition: "background-color 0.3s",
|
||||
}}
|
||||
>
|
||||
@@ -187,7 +185,7 @@ const ProxyControlSwitches = ({ label, onError }: ProxySwitchProps) => {
|
||||
</Box>
|
||||
|
||||
<Box sx={{ display: "flex", alignItems: "center" }}>
|
||||
{isSidecarMode && (
|
||||
{!isTunAvailable && (
|
||||
<Tooltip title={t("Install Service")} arrow>
|
||||
<Button
|
||||
variant="outlined"
|
||||
@@ -221,7 +219,7 @@ const ProxyControlSwitches = ({ label, onError }: ProxySwitchProps) => {
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onChange={(e) => {
|
||||
if (isSidecarMode) {
|
||||
if (!isTunAvailable) {
|
||||
showNotice(
|
||||
"error",
|
||||
t("TUN requires Service Mode or Admin Mode"),
|
||||
@@ -233,7 +231,7 @@ const ProxyControlSwitches = ({ label, onError }: ProxySwitchProps) => {
|
||||
onChangeData({ enable_tun_mode: e });
|
||||
}}
|
||||
onGuard={(e) => {
|
||||
if (isSidecarMode) {
|
||||
if (!isTunAvailable) {
|
||||
showNotice(
|
||||
"error",
|
||||
t("TUN requires Service Mode or Admin Mode"),
|
||||
@@ -245,7 +243,7 @@ const ProxyControlSwitches = ({ label, onError }: ProxySwitchProps) => {
|
||||
return patchVerge({ enable_tun_mode: e });
|
||||
}}
|
||||
>
|
||||
<Switch edge="end" disabled={isSidecarMode} />
|
||||
<Switch edge="end" disabled={!isTunAvailable} />
|
||||
</GuardState>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
Reference in New Issue
Block a user