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