From e164e219bdf328fe025fa71317cdf48163158309 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Fri, 27 Sep 2024 21:57:22 +0800 Subject: [PATCH] code cleanup --- .../main/golang/native/tunnel/connectivity.go | 3 +-- core/src/main/golang/native/tunnel/proxies.go | 16 +++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/core/src/main/golang/native/tunnel/connectivity.go b/core/src/main/golang/native/tunnel/connectivity.go index 7a89edac..be716784 100644 --- a/core/src/main/golang/native/tunnel/connectivity.go +++ b/core/src/main/golang/native/tunnel/connectivity.go @@ -3,7 +3,6 @@ package tunnel import ( "sync" - "github.com/metacubex/mihomo/adapter" "github.com/metacubex/mihomo/adapter/outboundgroup" "github.com/metacubex/mihomo/constant/provider" "github.com/metacubex/mihomo/log" @@ -19,7 +18,7 @@ func HealthCheck(name string) { return } - g, ok := p.(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup) + g, ok := p.Adapter().(outboundgroup.ProxyGroup) if !ok { log.Warnln("Request health check for `%s`: invalid type %s", name, p.Type().String()) diff --git a/core/src/main/golang/native/tunnel/proxies.go b/core/src/main/golang/native/tunnel/proxies.go index 8a402185..83ad15ec 100644 --- a/core/src/main/golang/native/tunnel/proxies.go +++ b/core/src/main/golang/native/tunnel/proxies.go @@ -6,8 +6,6 @@ import ( "github.com/dlclark/regexp2" - "github.com/metacubex/mihomo/adapter" - "github.com/metacubex/mihomo/adapter/outboundgroup" C "github.com/metacubex/mihomo/constant" "github.com/metacubex/mihomo/constant/provider" @@ -61,7 +59,7 @@ func QueryProxyGroupNames(excludeNotSelectable bool) []string { return []string{} } - global := tunnel.Proxies()["GLOBAL"].(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup) + global := tunnel.Proxies()["GLOBAL"].Adapter().(outboundgroup.ProxyGroup) proxies := global.Providers()[0].Proxies() result := make([]string, 0, len(proxies)+1) @@ -70,7 +68,7 @@ func QueryProxyGroupNames(excludeNotSelectable bool) []string { } for _, p := range proxies { - if _, ok := p.(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup); ok { + if _, ok := p.Adapter().(outboundgroup.ProxyGroup); ok { if !excludeNotSelectable || p.Type() == C.Selector { result = append(result, p.Name()) } @@ -89,7 +87,7 @@ func QueryProxyGroup(name string, sortMode SortMode, uiSubtitlePattern *regexp2. return nil } - g, ok := p.(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup) + g, ok := p.Adapter().(outboundgroup.ProxyGroup) if !ok { log.Warnln("Query group `%s`: invalid type %s", name, p.Type().String()) @@ -138,14 +136,14 @@ func PatchSelector(selector, name string) bool { return false } - g, ok := p.(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup) + g, ok := p.Adapter().(outboundgroup.ProxyGroup) if !ok { log.Warnln("Patch selector `%s`: invalid type %s", selector, p.Type().String()) return false } - s, ok := g.(*outboundgroup.Selector) + s, ok := g.(outboundgroup.SelectAble) if !ok { log.Warnln("Patch selector `%s`: invalid type %s", selector, p.Type().String()) @@ -172,7 +170,7 @@ func convertProxies(proxies []C.Proxy, uiSubtitlePattern *regexp2.Regexp) []*Pro subtitle := p.Type().String() if uiSubtitlePattern != nil { - if _, ok := p.(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup); !ok { + if _, ok := p.Adapter().(outboundgroup.ProxyGroup); !ok { runes := []rune(name) match, err := uiSubtitlePattern.FindRunesMatch(runes) if err == nil && match != nil { @@ -210,7 +208,7 @@ func collectProviders(providers []provider.ProxyProvider, uiSubtitlePattern *reg subtitle := px.Type().String() if uiSubtitlePattern != nil { - if _, ok := px.(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup); !ok { + if _, ok := px.Adapter().(outboundgroup.ProxyGroup); !ok { runes := []rune(name) match, err := uiSubtitlePattern.FindRunesMatch(runes) if err == nil && match != nil {