- {hydrationChip && (
-
- {hydrationChip}
-
- )}
+ {/* 代理组导航栏 */}
{mode === "rule" && (
{
)}
/>
- {showHydrationOverlay && overlayMessage && (
-
-
-
- {overlayMessage}
-
-
-
- )}
);
};
diff --git a/src/components/proxy/use-render-list.ts b/src/components/proxy/use-render-list.ts
index 1e6e0fd6a..7a5949ae3 100644
--- a/src/components/proxy/use-render-list.ts
+++ b/src/components/proxy/use-render-list.ts
@@ -14,13 +14,50 @@ import {
} from "./use-head-state";
import { useWindowWidth } from "./use-window-width";
-type RenderGroup = IProxyGroupItem;
+// 定义代理项接口
+interface IProxyItem {
+ name: string;
+ type: string;
+ udp: boolean;
+ xudp: boolean;
+ tfo: boolean;
+ mptcp: boolean;
+ smux: boolean;
+ history: {
+ time: string;
+ delay: number;
+ }[];
+ provider?: string;
+ testUrl?: string;
+ [key: string]: any; // 添加索引签名以适应其他可能的属性
+}
+
+// 代理组类型
+type ProxyGroup = {
+ name: string;
+ type: string;
+ udp: boolean;
+ xudp: boolean;
+ tfo: boolean;
+ mptcp: boolean;
+ smux: boolean;
+ history: {
+ time: string;
+ delay: number;
+ }[];
+ now: string;
+ all: IProxyItem[];
+ hidden?: boolean;
+ icon?: string;
+ testUrl?: string;
+ provider?: string;
+};
export interface IRenderItem {
// 组 | head | item | empty | item col
type: 0 | 1 | 2 | 3 | 4;
key: string;
- group: RenderGroup;
+ group: ProxyGroup;
proxy?: IProxyItem;
col?: number;
proxyCol?: IProxyItem[];
@@ -62,7 +99,7 @@ export const useRenderList = (
selectedGroup?: string | null,
) => {
// 使用全局数据提供者
- const { proxies: proxiesData, proxyHydration, refreshProxy } = useAppData();
+ const { proxies: proxiesData, refreshProxy } = useAppData();
const { verge } = useVerge();
const { width } = useWindowWidth();
const [headStates, setHeadState] = useHeadStateNew();
@@ -86,29 +123,17 @@ export const useRenderList = (
// 确保代理数据加载
useEffect(() => {
- if (!proxiesData || proxyHydration !== "live") return;
+ if (!proxiesData) return;
const { groups, proxies } = proxiesData;
if (
(mode === "rule" && !groups.length) ||
(mode === "global" && proxies.length < 2)
) {
- const handle = setTimeout(() => {
- void refreshProxy().catch(() => {});
- }, 500);
+ const handle = setTimeout(() => refreshProxy(), 500);
return () => clearTimeout(handle);
}
- }, [proxiesData, proxyHydration, mode, refreshProxy]);
-
- useEffect(() => {
- if (proxyHydration !== "snapshot") return;
-
- const handle = setTimeout(() => {
- void refreshProxy().catch(() => {});
- }, 1800);
-
- return () => clearTimeout(handle);
- }, [proxyHydration, refreshProxy]);
+ }, [proxiesData, mode, refreshProxy]);
// 链式代理模式节点自动计算延迟
useEffect(() => {
@@ -122,7 +147,7 @@ export const useRenderList = (
// 设置组监听器,当有延迟更新时自动刷新
const groupListener = () => {
console.log("[ChainMode] 延迟更新,刷新UI");
- void refreshProxy().catch(() => {});
+ refreshProxy();
};
delayManager.setGroupListener("chain-mode", groupListener);
@@ -163,12 +188,9 @@ export const useRenderList = (
// 链式代理模式下,显示代理组和其节点
if (isChainMode && runtimeConfig && mode === "rule") {
// 使用正常的规则模式代理组
- const chainGroups = proxiesData.groups ?? [];
- const allGroups = chainGroups.length
- ? chainGroups
- : proxiesData.global
- ? [proxiesData.global]
- : [];
+ const allGroups = proxiesData.groups.length
+ ? proxiesData.groups
+ : [proxiesData.global!];
// 如果选择了特定代理组,只显示该组的节点
if (selectedGroup) {
@@ -260,7 +282,7 @@ export const useRenderList = (
});
// 创建一个虚拟的组来容纳所有节点
- const virtualGroup: RenderGroup = {
+ const virtualGroup: ProxyGroup = {
name: "All Proxies",
type: "Selector",
udp: false,
@@ -318,7 +340,7 @@ export const useRenderList = (
});
// 创建一个虚拟的组来容纳所有节点
- const virtualGroup: RenderGroup = {
+ const virtualGroup: ProxyGroup = {
name: "All Proxies",
type: "Selector",
udp: false,
@@ -358,15 +380,12 @@ export const useRenderList = (
// 正常模式的渲染逻辑
const useRule = mode === "rule" || mode === "script";
- const renderGroups = (() => {
- const groups = proxiesData.groups ?? [];
- if (useRule && groups.length) {
- return groups;
- }
- return proxiesData.global ? [proxiesData.global] : groups;
- })();
+ const renderGroups =
+ useRule && proxiesData.groups.length
+ ? proxiesData.groups
+ : [proxiesData.global!];
- const retList = renderGroups.flatMap((group: RenderGroup) => {
+ const retList = renderGroups.flatMap((group: ProxyGroup) => {
const headState = headStates[group.name] || DEFAULT_STATE;
const ret: IRenderItem[] = [
{
diff --git a/src/hooks/use-current-proxy.ts b/src/hooks/use-current-proxy.ts
index 0c7108ffb..7d3523269 100644
--- a/src/hooks/use-current-proxy.ts
+++ b/src/hooks/use-current-proxy.ts
@@ -2,6 +2,12 @@ import { useMemo } from "react";
import { useAppData } from "@/providers/app-data-context";
+// 定义代理组类型
+interface ProxyGroup {
+ name: string;
+ now: string;
+}
+
// 获取当前代理节点信息的自定义Hook
export const useCurrentProxy = () => {
// 从AppDataProvider获取数据
@@ -31,15 +37,15 @@ export const useCurrentProxy = () => {
"自动选择",
];
const primaryGroup =
- groups.find((group) =>
+ groups.find((group: ProxyGroup) =>
primaryKeywords.some((keyword) =>
group.name.toLowerCase().includes(keyword.toLowerCase()),
),
- ) || groups.find((group) => group.name !== "GLOBAL");
+ ) || groups.filter((g: ProxyGroup) => g.name !== "GLOBAL")[0];
if (primaryGroup) {
primaryGroupName = primaryGroup.name;
- currentName = primaryGroup.now ?? currentName;
+ currentName = primaryGroup.now;
}
}
diff --git a/src/hooks/use-profiles.ts b/src/hooks/use-profiles.ts
index c412ec307..fdb734627 100644
--- a/src/hooks/use-profiles.ts
+++ b/src/hooks/use-profiles.ts
@@ -5,54 +5,33 @@ import {
getProfiles,
patchProfile,
patchProfilesConfig,
- calcuProxies,
} from "@/services/cmds";
-import {
- useProfileStore,
- selectEffectiveProfiles,
- selectIsHydrating,
- selectLastResult,
-} from "@/stores/profile-store";
+import { calcuProxies } from "@/services/cmds";
export const useProfiles = () => {
- const profilesFromStore = useProfileStore(selectEffectiveProfiles);
- const storeHydrating = useProfileStore(selectIsHydrating);
- const lastResult = useProfileStore(selectLastResult);
- const commitProfileSnapshot = useProfileStore(
- (state) => state.commitHydrated,
- );
-
const {
- data: swrProfiles,
+ data: profiles,
mutate: mutateProfiles,
error,
isValidating,
} = useSWR("getProfiles", getProfiles, {
revalidateOnFocus: false,
revalidateOnReconnect: false,
- dedupingInterval: 500,
+ dedupingInterval: 500, // 减少去重时间,提高响应性
errorRetryCount: 3,
errorRetryInterval: 1000,
- refreshInterval: 0,
- onError: (err) => {
- console.error("[useProfiles] SWR错误:", err);
+ refreshInterval: 0, // 完全由手动控制
+ onError: (error) => {
+ console.error("[useProfiles] SWR错误:", error);
},
onSuccess: (data) => {
- commitProfileSnapshot(data);
console.log(
- "[useProfiles] 配置数据更新成功,配置数量",
+ "[useProfiles] 配置数据更新成功,配置数量:",
data?.items?.length || 0,
);
},
});
- const rawProfiles = profilesFromStore ?? swrProfiles;
- const profiles = (rawProfiles ?? {
- current: null,
- items: [],
- }) as IProfilesConfig;
- const hasProfiles = rawProfiles != null;
-
const patchProfiles = async (
value: Partial