diff --git a/core/src/main/golang/native/config/provider_open.go b/core/src/main/golang/native/config/provider_open.go index 655aedee..f0bdad2b 100644 --- a/core/src/main/golang/native/config/provider_open.go +++ b/core/src/main/golang/native/config/provider_open.go @@ -9,7 +9,7 @@ import ( ) func forEachProviders(rawCfg *config.RawConfig, fun func(index int, total int, key string, provider map[string]any)) { - total := len(rawCfg.ProxyProvider) + total := len(rawCfg.ProxyProvider) + len(rawCfg.RuleProvider) index := 0 for k, v := range rawCfg.ProxyProvider { @@ -17,10 +17,20 @@ func forEachProviders(rawCfg *config.RawConfig, fun func(index int, total int, k index++ } + + for k, v := range rawCfg.RuleProvider { + fun(index, total, k, v) + + index++ + } } func destroyProviders(cfg *config.Config) { for _, p := range cfg.Providers { _ = p.(io.Closer).Close() } + + for _, p := range cfg.RuleProviders { + _ = p.(io.Closer).Close() + } } diff --git a/core/src/main/golang/native/tunnel/providers_open.go b/core/src/main/golang/native/tunnel/providers_open.go index 9bf576d7..d4059584 100644 --- a/core/src/main/golang/native/tunnel/providers_open.go +++ b/core/src/main/golang/native/tunnel/providers_open.go @@ -3,14 +3,18 @@ package tunnel import ( + "errors" "fmt" "time" P "github.com/Dreamacro/clash/adapter/provider" "github.com/Dreamacro/clash/constant/provider" + "github.com/Dreamacro/clash/log" "github.com/Dreamacro/clash/tunnel" ) +var ErrInvalidType = errors.New("invalid type") + type Provider struct { Name string `json:"name"` VehicleType string `json:"vehicleType"` @@ -19,9 +23,18 @@ type Provider struct { } func QueryProviders() []*Provider { + r := tunnel.RuleProviders() p := tunnel.Providers() - providers := make([]provider.Provider, 0, len(p)) + providers := make([]provider.Provider, 0, len(r)+len(p)) + + for _, rule := range r { + if rule.VehicleType() == provider.Compatible { + continue + } + + providers = append(providers, rule) + } for _, proxy := range p { if proxy.VehicleType() == provider.Compatible { @@ -51,11 +64,29 @@ func QueryProviders() []*Provider { return result } -func UpdateProvider(_ string, name string) error { - p, ok := tunnel.Providers()[name] - if !ok { - return fmt.Errorf("%s not found", name) +func UpdateProvider(t string, name string) error { + err := ErrInvalidType + + switch t { + case "Rule": + p := tunnel.RuleProviders()[name] + if p == nil { + return fmt.Errorf("%s not found", name) + } + + err = p.Update() + case "Proxy": + p := tunnel.Providers()[name] + if p == nil { + return fmt.Errorf("%s not found", name) + } + + err = p.Update() } - return p.Update() + if err != nil { + log.Warnln("Updating provider %s: %s", name, err.Error()) + } + + return err } diff --git a/core/src/main/java/com/github/kr328/clash/core/model/Proxy.kt b/core/src/main/java/com/github/kr328/clash/core/model/Proxy.kt index 0bcf66e9..ea6f6704 100644 --- a/core/src/main/java/com/github/kr328/clash/core/model/Proxy.kt +++ b/core/src/main/java/com/github/kr328/clash/core/model/Proxy.kt @@ -17,6 +17,8 @@ data class Proxy( enum class Type(val group: Boolean) { Direct(false), Reject(false), + Compatible(false), + Pass(false), Shadowsocks(false), ShadowsocksR(false), @@ -24,7 +26,10 @@ data class Proxy( Socks5(false), Http(false), Vmess(false), + Vless(false), Trojan(false), + Hysteria(false), + Relay(true), Selector(true),