mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
Fix getDelayFix hook issue
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
- 同步更新多语言翻译
|
||||
- 修复 .window-state.json 无法删除的问题
|
||||
- 无法修改配置更新 HTTP 请求超时
|
||||
- 修复 getDelayFix 钩子问题
|
||||
|
||||
#### 新增了:
|
||||
- Mihomo(Meta)内核升级至 1.19.8
|
||||
|
||||
@@ -128,7 +128,7 @@ export const CurrentProxyCard = () => {
|
||||
groups: [],
|
||||
records: {},
|
||||
globalProxy: "",
|
||||
directProxy: null,
|
||||
directProxy: { name: "DIRECT" }, // 默认值避免 undefined
|
||||
},
|
||||
selection: {
|
||||
group: "",
|
||||
@@ -213,7 +213,7 @@ export const CurrentProxyCard = () => {
|
||||
if (isDirectMode) {
|
||||
newGroup = "DIRECT";
|
||||
newProxy = "DIRECT";
|
||||
newDisplayProxy = proxies.records?.DIRECT || null;
|
||||
newDisplayProxy = proxies.records?.DIRECT || { name: "DIRECT" }; // 确保非空
|
||||
} else if (isGlobalMode && proxies.global) {
|
||||
newGroup = "GLOBAL";
|
||||
newProxy = proxies.global.now || "";
|
||||
@@ -248,7 +248,7 @@ export const CurrentProxyCard = () => {
|
||||
groups: filteredGroups,
|
||||
records: proxies.records || {},
|
||||
globalProxy: proxies.global?.now || "",
|
||||
directProxy: proxies.records?.DIRECT || null,
|
||||
directProxy: proxies.records?.DIRECT || { name: "DIRECT" },
|
||||
},
|
||||
selection: {
|
||||
group: newGroup,
|
||||
@@ -364,12 +364,15 @@ export const CurrentProxyCard = () => {
|
||||
return state.displayProxy;
|
||||
}, [state.displayProxy]);
|
||||
|
||||
// 获取当前节点的延迟
|
||||
const currentDelay = currentProxy
|
||||
// 获取当前节点的延迟(增加非空校验)
|
||||
const currentDelay = currentProxy && state.selection.group
|
||||
? delayManager.getDelayFix(currentProxy, state.selection.group)
|
||||
: -1;
|
||||
|
||||
const signalInfo = getSignalIcon(currentDelay);
|
||||
// 信号图标(增加非空校验)
|
||||
const signalInfo = currentProxy && state.selection.group
|
||||
? getSignalIcon(currentDelay)
|
||||
: { icon: <SignalNone />, text: "未初始化", color: "text.secondary" };
|
||||
|
||||
// 自定义渲染选择框中的值
|
||||
const renderProxyValue = useCallback(
|
||||
@@ -378,7 +381,7 @@ export const CurrentProxyCard = () => {
|
||||
|
||||
const delayValue = delayManager.getDelayFix(
|
||||
state.proxyData.records[selected],
|
||||
state.selection.group,
|
||||
state.selection.group
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -402,23 +405,27 @@ export const CurrentProxyCard = () => {
|
||||
localStorage.setItem(STORAGE_KEY_SORT_TYPE, newSortType.toString());
|
||||
}, [sortType]);
|
||||
|
||||
// 排序代理函数
|
||||
// 排序代理函数(增加非空校验)
|
||||
const sortProxies = useCallback(
|
||||
(proxies: ProxyOption[]) => {
|
||||
if (!proxies || sortType === 0) return proxies;
|
||||
|
||||
// 确保数据存在
|
||||
if (!state.proxyData.records || !state.selection.group) return proxies;
|
||||
|
||||
const list = [...proxies];
|
||||
|
||||
if (sortType === 1) {
|
||||
list.sort((a, b) => {
|
||||
const ad = delayManager.getDelayFix(
|
||||
state.proxyData.records[a.name],
|
||||
state.selection.group
|
||||
);
|
||||
const bd = delayManager.getDelayFix(
|
||||
state.proxyData.records[b.name],
|
||||
state.selection.group
|
||||
);
|
||||
const recordA = state.proxyData.records[a.name];
|
||||
const recordB = state.proxyData.records[b.name];
|
||||
|
||||
// 处理 record 不存在的情况
|
||||
if (!recordA) return 1;
|
||||
if (!recordB) return -1;
|
||||
|
||||
const ad = delayManager.getDelayFix(recordA, state.selection.group);
|
||||
const bd = delayManager.getDelayFix(recordB, state.selection.group);
|
||||
|
||||
if (ad === -1 || ad === -2) return 1;
|
||||
if (bd === -1 || bd === -2) return -1;
|
||||
@@ -431,10 +438,10 @@ export const CurrentProxyCard = () => {
|
||||
|
||||
return list;
|
||||
},
|
||||
[sortType, state?.proxyData?.records, state?.selection?.group]
|
||||
[sortType, state.proxyData.records, state.selection.group]
|
||||
);
|
||||
|
||||
// 计算要显示的代理选项
|
||||
// 计算要显示的代理选项(增加非空校验)
|
||||
const proxyOptions = useMemo(() => {
|
||||
if (isDirectMode) {
|
||||
return [{ name: "DIRECT" }];
|
||||
@@ -453,13 +460,15 @@ export const CurrentProxyCard = () => {
|
||||
}
|
||||
|
||||
// 规则模式
|
||||
const group = state.proxyData.groups.find(
|
||||
(g: { name: string }) => g.name === state.selection.group,
|
||||
);
|
||||
const group = state.selection.group
|
||||
? state.proxyData.groups.find(g => g.name === state.selection.group)
|
||||
: null;
|
||||
|
||||
if (group) {
|
||||
const options = group.all.map((name) => ({ name }));
|
||||
return sortProxies(options);
|
||||
}
|
||||
|
||||
return [];
|
||||
}, [isDirectMode, isGlobalMode, proxies, state.proxyData, state.selection.group, sortProxies]);
|
||||
|
||||
@@ -648,10 +657,12 @@ export const CurrentProxyCard = () => {
|
||||
{isDirectMode
|
||||
? null
|
||||
: proxyOptions.map((proxy, index) => {
|
||||
const delayValue = delayManager.getDelayFix(
|
||||
const delayValue = state.proxyData.records[proxy.name] && state.selection.group
|
||||
? delayManager.getDelayFix(
|
||||
state.proxyData.records[proxy.name],
|
||||
state.selection.group,
|
||||
);
|
||||
)
|
||||
: -1;
|
||||
return (
|
||||
<MenuItem
|
||||
key={`${proxy.name}-${index}`}
|
||||
|
||||
Reference in New Issue
Block a user