From cfc35e102838500c21a84c05947e15aa155114ed Mon Sep 17 00:00:00 2001 From: Howard Cheung Date: Sun, 4 Sep 2022 14:55:18 +0800 Subject: [PATCH] fix: proxy providers not filtered in proxy groups --- core/src/main/golang/native/tunnel/proxies.go | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/core/src/main/golang/native/tunnel/proxies.go b/core/src/main/golang/native/tunnel/proxies.go index 44d9b3ed..5cdfe43e 100644 --- a/core/src/main/golang/native/tunnel/proxies.go +++ b/core/src/main/golang/native/tunnel/proxies.go @@ -96,7 +96,8 @@ func QueryProxyGroup(name string, sortMode SortMode, uiSubtitlePattern *regexp2. return nil } - proxies := collectProviders(g.Providers(), uiSubtitlePattern) + proxies := convertProxies(g.Proxies(), uiSubtitlePattern) + //proxies := collectProviders(g.Providers(), uiSubtitlePattern) switch sortMode { case Title: @@ -162,6 +163,36 @@ func PatchSelector(selector, name string) bool { return true } +func convertProxies(proxies []C.Proxy, uiSubtitlePattern *regexp2.Regexp) []*Proxy { + result := make([]*Proxy, 0, 128) + + for _, p := range proxies { + name := p.Name() + title := name + subtitle := p.Type().String() + + if uiSubtitlePattern != nil { + if _, ok := p.(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup); !ok { + runes := []rune(name) + match, err := uiSubtitlePattern.FindRunesMatch(runes) + if err == nil && match != nil { + title = string(runes[:match.Index]) + string(runes[match.Index+match.Length:]) + subtitle = string(runes[match.Index : match.Index+match.Length]) + } + } + } + + result = append(result, &Proxy{ + Name: name, + Title: strings.TrimSpace(title), + Subtitle: strings.TrimSpace(subtitle), + Type: p.Type().String(), + Delay: int(p.LastDelay()), + }) + } + return result +} + func collectProviders(providers []provider.ProxyProvider, uiSubtitlePattern *regexp2.Regexp) []*Proxy { result := make([]*Proxy, 0, 128)