fix(proxy): update group selection logic to skip empty and default names

This commit is contained in:
Chang lue Tsen 2025-07-16 14:27:16 -04:00 committed by Leif Draven
parent 8c4c7d0773
commit 82e447c55e

View File

@ -245,7 +245,7 @@ func FindDefaultGroup(groups []*server.RuleGroup) string {
return group.Name return group.Name
} }
} }
return "智能线路" return AutoSelect
} }
// SortGroups sorts the provided slice of proxy groups by their names. // SortGroups sorts the provided slice of proxy groups by their names.
@ -254,6 +254,9 @@ func SortGroups(groups []proxy.Group, defaultName string) []proxy.Group {
var selectedGroup proxy.Group var selectedGroup proxy.Group
// 在所有分组找到默认分组并将他放到第一个 // 在所有分组找到默认分组并将他放到第一个
for _, group := range groups { for _, group := range groups {
if group.Name == "" || group.Name == "DIRECT" || group.Name == "REJECT" {
continue
}
if group.Name == defaultName { if group.Name == defaultName {
group.Proxies = tool.RemoveStringElement(group.Proxies, defaultName, "REJECT") group.Proxies = tool.RemoveStringElement(group.Proxies, defaultName, "REJECT")
sortedGroups = append([]proxy.Group{group}, sortedGroups...) sortedGroups = append([]proxy.Group{group}, sortedGroups...)
@ -276,17 +279,3 @@ func SortGroups(groups []proxy.Group, defaultName string) []proxy.Group {
return sortedGroups return sortedGroups
} }
// RemoveElementByName removes elements from the slice of proxy groups by their names.
func RemoveElementByName(groups []proxy.Group, names ...string) []proxy.Group {
for i := 0; i < len(groups); i++ {
for _, name := range names {
if groups[i].Name == name {
groups = append(groups[:i], groups[i+1:]...)
i-- // Adjust index after removal
break // Exit inner loop to avoid index out of range
}
}
}
return groups
}