Feature: add mode script

This commit is contained in:
yaling888
2021-10-15 14:11:14 +08:00
parent 862174d21b
commit c0e9d69163
28 changed files with 1918 additions and 356 deletions

View File

@ -18,6 +18,7 @@ import (
"github.com/Dreamacro/clash/component/profile"
"github.com/Dreamacro/clash/component/profile/cachefile"
"github.com/Dreamacro/clash/component/resolver"
S "github.com/Dreamacro/clash/component/script"
"github.com/Dreamacro/clash/component/trie"
"github.com/Dreamacro/clash/config"
C "github.com/Dreamacro/clash/constant"
@ -68,6 +69,9 @@ func ParseWithPath(path string) (*config.Config, error) {
// ParseWithBytes config with buffer
func ParseWithBytes(buf []byte) (*config.Config, error) {
mux.Lock()
defer mux.Unlock()
return config.Parse(buf)
}
@ -79,6 +83,7 @@ func ApplyConfig(cfg *config.Config, force bool) {
updateUsers(cfg.Users)
updateProxies(cfg.Proxies, cfg.Providers)
updateRules(cfg.Rules)
updateRuleProviders(cfg.RuleProviders)
updateHosts(cfg.Hosts)
updateProfile(cfg)
updateIPTables(cfg.DNS, cfg.General)
@ -179,6 +184,10 @@ func updateRules(rules []C.Rule) {
tunnel.UpdateRules(rules)
}
func updateRuleProviders(providers map[string]C.Rule) {
S.UpdateRuleProviders(providers)
}
func updateGeneral(general *config.General, force bool) {
tunnel.SetMode(general.Mode)
resolver.DisableIPv6 = !general.IPv6
@ -321,4 +330,6 @@ func CleanUp() {
if runtime.GOOS == "linux" {
tproxy.CleanUpTProxyLinuxIPTables()
}
S.Py_Finalize()
}