Revert "refactor: profile switch (#5197)"

This reverts commit c2dcd86722.
This commit is contained in:
Tunglies
2025-10-30 18:11:04 +08:00
parent 928f226d10
commit a869dbb441
36 changed files with 1257 additions and 5894 deletions
+54 -35
View File
@@ -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[] = [
{