Refactor: allow to add an empty proxy provider to proxy group

This commit is contained in:
yaling888
2022-06-22 04:36:27 +08:00
parent e31be4edc2
commit 1f12ef069b
7 changed files with 76 additions and 48 deletions

View File

@@ -3,6 +3,8 @@ package outboundgroup
import (
"time"
"github.com/Dreamacro/clash/adapter"
"github.com/Dreamacro/clash/adapter/outbound"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/constant/provider"
)
@@ -11,14 +13,19 @@ const (
defaultGetProxiesDuration = time.Second * 5
)
var defaultRejectProxy = adapter.NewProxy(outbound.NewReject())
func getProvidersProxies(providers []provider.ProxyProvider, touch bool) []C.Proxy {
proxies := []C.Proxy{}
for _, provider := range providers {
for _, pd := range providers {
if touch {
proxies = append(proxies, provider.ProxiesWithTouch()...)
proxies = append(proxies, pd.ProxiesWithTouch()...)
} else {
proxies = append(proxies, provider.Proxies()...)
proxies = append(proxies, pd.Proxies()...)
}
}
if len(proxies) == 0 {
proxies = append(proxies, defaultRejectProxy)
}
return proxies
}