fix: add fallback to first proxy in group if 'now' is missing and prioritize selector-type groups

- When the current group or its 'now' field is missing, fallback to the first proxy in the group's list to ensure a valid active node is always selected.
- When no current group is found, prioritize groups of type 'Selector' for selection, improving compatibility with custom or extended proxy groups.
This commit is contained in:
Tunglies
2025-05-22 10:10:26 +08:00
parent 9af0803e9b
commit b4595d7886

View File

@@ -223,21 +223,23 @@ export const CurrentProxyCard = () => {
(g: { name: string }) => g.name === prev.selection.group,
);
// 如果当前组不存在或为空,自动选择第一个组
// 如果当前组不存在或为空,自动选择第一个 selector 类型的
if (!currentGroup && filteredGroups.length > 0) {
newGroup = filteredGroups[0].name;
const firstGroup = filteredGroups[0];
newProxy = firstGroup.now;
newDisplayProxy = proxies.records?.[newProxy] || null;
const selectorGroup = filteredGroups.find((g: { type: string }) => g.type === "Selector");
if (selectorGroup) {
newGroup = selectorGroup.name;
newProxy = selectorGroup.now || selectorGroup.all[0] || "";
newDisplayProxy = proxies.records?.[newProxy] || null;
if (!isGlobalMode && !isDirectMode) {
localStorage.setItem(STORAGE_KEY_GROUP, newGroup);
if (newProxy) {
localStorage.setItem(STORAGE_KEY_PROXY, newProxy);
if (!isGlobalMode && !isDirectMode) {
localStorage.setItem(STORAGE_KEY_GROUP, newGroup);
if (newProxy) {
localStorage.setItem(STORAGE_KEY_PROXY, newProxy);
}
}
}
} else if (currentGroup) {
newProxy = currentGroup.now;
newProxy = currentGroup.now || currentGroup.all[0] || "";
newDisplayProxy = proxies.records?.[newProxy] || null;
}
}