feat: unify TUN mode availability checks across components
This commit is contained in:
@@ -142,13 +142,11 @@ export const ProxyTunCard: FC = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const { verge } = useVerge();
|
const { verge } = useVerge();
|
||||||
const { isAdminMode, isServiceMode } = useSystemState();
|
const { isTunModeAvailable } = useSystemState();
|
||||||
const { actualState: systemProxyActualState } = useSystemProxyState();
|
const { actualState: systemProxyActualState } = useSystemProxyState();
|
||||||
|
|
||||||
const { enable_tun_mode } = verge ?? {};
|
const { enable_tun_mode } = verge ?? {};
|
||||||
|
|
||||||
const isTunAvailable = isServiceMode || isAdminMode;
|
|
||||||
|
|
||||||
const handleError = (err: Error) => {
|
const handleError = (err: Error) => {
|
||||||
showNotice("error", err.message || err.toString());
|
showNotice("error", err.message || err.toString());
|
||||||
};
|
};
|
||||||
@@ -168,7 +166,7 @@ export const ProxyTunCard: FC = () => {
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
text: !isTunAvailable
|
text: !isTunModeAvailable
|
||||||
? t("TUN Mode Service Required")
|
? t("TUN Mode Service Required")
|
||||||
: enable_tun_mode
|
: enable_tun_mode
|
||||||
? t("TUN Mode Enabled")
|
? t("TUN Mode Enabled")
|
||||||
@@ -176,7 +174,13 @@ export const ProxyTunCard: FC = () => {
|
|||||||
tooltip: t("TUN Mode Intercept Info"),
|
tooltip: t("TUN Mode Intercept Info"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, [activeTab, systemProxyActualState, enable_tun_mode, isTunAvailable, t]);
|
}, [
|
||||||
|
activeTab,
|
||||||
|
systemProxyActualState,
|
||||||
|
enable_tun_mode,
|
||||||
|
isTunModeAvailable,
|
||||||
|
t,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ display: "flex", flexDirection: "column", width: "100%" }}>
|
<Box sx={{ display: "flex", flexDirection: "column", width: "100%" }}>
|
||||||
@@ -202,7 +206,7 @@ export const ProxyTunCard: FC = () => {
|
|||||||
onClick={() => handleTabChange("tun")}
|
onClick={() => handleTabChange("tun")}
|
||||||
icon={TroubleshootRounded}
|
icon={TroubleshootRounded}
|
||||||
label={t("Tun Mode")}
|
label={t("Tun Mode")}
|
||||||
hasIndicator={enable_tun_mode && isTunAvailable}
|
hasIndicator={enable_tun_mode && isTunModeAvailable}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
|
|||||||
@@ -189,11 +189,11 @@ const ProxyControlSwitches = ({
|
|||||||
onInfoClick={() => tunRef.current?.open()}
|
onInfoClick={() => tunRef.current?.open()}
|
||||||
onToggle={handleTunToggle}
|
onToggle={handleTunToggle}
|
||||||
onError={onError}
|
onError={onError}
|
||||||
disabled={!isServiceMode}
|
disabled={!isTunModeAvailable}
|
||||||
highlight={!!enable_tun_mode}
|
highlight={!!enable_tun_mode}
|
||||||
extraIcons={
|
extraIcons={
|
||||||
<>
|
<>
|
||||||
{!isServiceMode && (
|
{!isTunModeAvailable && (
|
||||||
<TooltipIcon
|
<TooltipIcon
|
||||||
title={t("TUN requires Service Mode or Admin Mode")}
|
title={t("TUN requires Service Mode or Admin Mode")}
|
||||||
icon={WarningRounded}
|
icon={WarningRounded}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { showNotice } from "@/services/noticeService";
|
|||||||
|
|
||||||
export const useVerge = () => {
|
export const useVerge = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { isAdminMode, isServiceMode } = useSystemState();
|
const { isAdminMode, isServiceOk } = useSystemState();
|
||||||
|
|
||||||
const { data: verge, mutate: mutateVerge } = useSWR(
|
const { data: verge, mutate: mutateVerge } = useSWR(
|
||||||
"getVergeConfig",
|
"getVergeConfig",
|
||||||
@@ -23,7 +23,7 @@ export const useVerge = () => {
|
|||||||
mutateVerge();
|
mutateVerge();
|
||||||
};
|
};
|
||||||
|
|
||||||
const isTunAvailable = isServiceMode || isAdminMode;
|
const isTunAvailable = isAdminMode || isServiceOk;
|
||||||
const { enable_tun_mode } = verge ?? {};
|
const { enable_tun_mode } = verge ?? {};
|
||||||
|
|
||||||
// 当服务不可用且TUN模式开启时自动关闭TUN
|
// 当服务不可用且TUN模式开启时自动关闭TUN
|
||||||
|
|||||||
Reference in New Issue
Block a user