code cleanup

This commit is contained in:
wwqgtxx 2024-09-27 21:57:22 +08:00
parent 309726dddd
commit e164e219bd
2 changed files with 8 additions and 11 deletions

View File

@ -3,7 +3,6 @@ package tunnel
import ( import (
"sync" "sync"
"github.com/metacubex/mihomo/adapter"
"github.com/metacubex/mihomo/adapter/outboundgroup" "github.com/metacubex/mihomo/adapter/outboundgroup"
"github.com/metacubex/mihomo/constant/provider" "github.com/metacubex/mihomo/constant/provider"
"github.com/metacubex/mihomo/log" "github.com/metacubex/mihomo/log"
@ -19,7 +18,7 @@ func HealthCheck(name string) {
return return
} }
g, ok := p.(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup) g, ok := p.Adapter().(outboundgroup.ProxyGroup)
if !ok { if !ok {
log.Warnln("Request health check for `%s`: invalid type %s", name, p.Type().String()) log.Warnln("Request health check for `%s`: invalid type %s", name, p.Type().String())

View File

@ -6,8 +6,6 @@ import (
"github.com/dlclark/regexp2" "github.com/dlclark/regexp2"
"github.com/metacubex/mihomo/adapter"
"github.com/metacubex/mihomo/adapter/outboundgroup" "github.com/metacubex/mihomo/adapter/outboundgroup"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/provider" "github.com/metacubex/mihomo/constant/provider"
@ -61,7 +59,7 @@ func QueryProxyGroupNames(excludeNotSelectable bool) []string {
return []string{} return []string{}
} }
global := tunnel.Proxies()["GLOBAL"].(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup) global := tunnel.Proxies()["GLOBAL"].Adapter().(outboundgroup.ProxyGroup)
proxies := global.Providers()[0].Proxies() proxies := global.Providers()[0].Proxies()
result := make([]string, 0, len(proxies)+1) result := make([]string, 0, len(proxies)+1)
@ -70,7 +68,7 @@ func QueryProxyGroupNames(excludeNotSelectable bool) []string {
} }
for _, p := range proxies { 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 { if !excludeNotSelectable || p.Type() == C.Selector {
result = append(result, p.Name()) result = append(result, p.Name())
} }
@ -89,7 +87,7 @@ func QueryProxyGroup(name string, sortMode SortMode, uiSubtitlePattern *regexp2.
return nil return nil
} }
g, ok := p.(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup) g, ok := p.Adapter().(outboundgroup.ProxyGroup)
if !ok { if !ok {
log.Warnln("Query group `%s`: invalid type %s", name, p.Type().String()) log.Warnln("Query group `%s`: invalid type %s", name, p.Type().String())
@ -138,14 +136,14 @@ func PatchSelector(selector, name string) bool {
return false return false
} }
g, ok := p.(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup) g, ok := p.Adapter().(outboundgroup.ProxyGroup)
if !ok { if !ok {
log.Warnln("Patch selector `%s`: invalid type %s", selector, p.Type().String()) log.Warnln("Patch selector `%s`: invalid type %s", selector, p.Type().String())
return false return false
} }
s, ok := g.(*outboundgroup.Selector) s, ok := g.(outboundgroup.SelectAble)
if !ok { if !ok {
log.Warnln("Patch selector `%s`: invalid type %s", selector, p.Type().String()) 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() subtitle := p.Type().String()
if uiSubtitlePattern != nil { if uiSubtitlePattern != nil {
if _, ok := p.(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup); !ok { if _, ok := p.Adapter().(outboundgroup.ProxyGroup); !ok {
runes := []rune(name) runes := []rune(name)
match, err := uiSubtitlePattern.FindRunesMatch(runes) match, err := uiSubtitlePattern.FindRunesMatch(runes)
if err == nil && match != nil { if err == nil && match != nil {
@ -210,7 +208,7 @@ func collectProviders(providers []provider.ProxyProvider, uiSubtitlePattern *reg
subtitle := px.Type().String() subtitle := px.Type().String()
if uiSubtitlePattern != nil { if uiSubtitlePattern != nil {
if _, ok := px.(*adapter.Proxy).ProxyAdapter.(outboundgroup.ProxyGroup); !ok { if _, ok := px.Adapter().(outboundgroup.ProxyGroup); !ok {
runes := []rune(name) runes := []rune(name)
match, err := uiSubtitlePattern.FindRunesMatch(runes) match, err := uiSubtitlePattern.FindRunesMatch(runes)
if err == nil && match != nil { if err == nil && match != nil {