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