🧹 Cleanup Summary: - Fixed 83 oxlint warnings across 50+ files - Removed unused imports, variables, and functions - Maintained all functional code and error handling - Improved bundle size and code maintainability 📝 Key Changes: - Cleaned unused React hooks (useState, useEffect, useClashInfo) - Removed unused Material-UI imports (useTheme, styled components) - Deleted unused interfaces and type definitions - Fixed spread operator usage and boolean casting - Simplified catch parameters where appropriate 🎯 Files Modified: - React components: home.tsx, settings, profiles, etc. - Custom hooks: use-*.ts files - Utility functions and type definitions - Configuration files ✅ Result: 0 oxlint warnings (from 83 warnings) 🔧 All functionality preserved 📦 Reduced bundle size through dead code elimination
79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
import useSWR, { mutate } from "swr";
|
|
import { useVerge } from "@/hooks/use-verge";
|
|
import { getAutotemProxy } from "@/services/cmds";
|
|
import { useAppData } from "@/providers/app-data-provider";
|
|
import { closeAllConnections } from "@/services/cmds";
|
|
|
|
// 系统代理状态检测统一逻辑
|
|
export const useSystemProxyState = () => {
|
|
const { verge, mutateVerge, patchVerge } = useVerge();
|
|
const { sysproxy } = useAppData();
|
|
const { data: autoproxy } = useSWR("getAutotemProxy", getAutotemProxy, {
|
|
revalidateOnFocus: true,
|
|
revalidateOnReconnect: true,
|
|
});
|
|
|
|
const { enable_system_proxy, proxy_auto_config } = verge ?? {};
|
|
|
|
const getSystemProxyActualState = () => {
|
|
const userEnabled = enable_system_proxy ?? false;
|
|
|
|
// 用户配置状态应该与系统实际状态一致
|
|
// 如果用户启用了系统代理,检查实际的系统状态
|
|
if (userEnabled) {
|
|
if (proxy_auto_config) {
|
|
return autoproxy?.enable ?? false;
|
|
} else {
|
|
return sysproxy?.enable ?? false;
|
|
}
|
|
}
|
|
|
|
// 用户没有启用时,返回 false
|
|
return false;
|
|
};
|
|
|
|
const getSystemProxyIndicator = () => {
|
|
if (proxy_auto_config) {
|
|
return autoproxy?.enable ?? false;
|
|
} else {
|
|
return sysproxy?.enable ?? false;
|
|
}
|
|
};
|
|
|
|
const updateProxyStatus = async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
await mutate("getSystemProxy");
|
|
await mutate("getAutotemProxy");
|
|
};
|
|
|
|
const toggleSystemProxy = (enabled: boolean) => {
|
|
mutateVerge({ ...verge, enable_system_proxy: enabled }, false);
|
|
|
|
setTimeout(async () => {
|
|
try {
|
|
if (!enabled && verge?.auto_close_connection) {
|
|
closeAllConnections();
|
|
}
|
|
await patchVerge({ enable_system_proxy: enabled });
|
|
|
|
updateProxyStatus();
|
|
} catch (error) {
|
|
console.warn("[useSystemProxyState] toggleSystemProxy failed:", error);
|
|
mutateVerge({ ...verge, enable_system_proxy: !enabled }, false);
|
|
}
|
|
}, 0);
|
|
|
|
return Promise.resolve();
|
|
};
|
|
|
|
return {
|
|
actualState: getSystemProxyActualState(),
|
|
indicator: getSystemProxyIndicator(),
|
|
configState: enable_system_proxy ?? false,
|
|
sysproxy,
|
|
autoproxy,
|
|
proxy_auto_config,
|
|
toggleSystemProxy,
|
|
};
|
|
};
|