Add apple-update rule for apple clients

This commit is contained in:
世界 2023-12-30 23:43:49 +08:00
parent 22d9c4991a
commit 2a3dabd58c
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
4 changed files with 32 additions and 12 deletions

View File

@ -1,9 +1,11 @@
package option package option
import ( import (
M "github.com/sagernet/serenity/common/metadata"
"github.com/sagernet/serenity/common/semver" "github.com/sagernet/serenity/common/semver"
"github.com/sagernet/sing-box/option" "github.com/sagernet/sing-box/option"
dns "github.com/sagernet/sing-dns" "github.com/sagernet/sing-dns"
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/json/badjson" "github.com/sagernet/sing/common/json/badjson"
) )
@ -67,6 +69,20 @@ func (t Template) DisableIPv6() bool {
return t.DomainStrategy == option.DomainStrategy(dns.DomainStrategyUseIPv4) return t.DomainStrategy == option.DomainStrategy(dns.DomainStrategyUseIPv4)
} }
func (t Template) ChinaGeositeList(metadata M.Metadata) []string {
chinaCodes := []string{"cn", "category-companies@cn"}
if metadata.Platform.IsApple() {
chinaCodes = append(chinaCodes, "apple-update")
}
return chinaCodes
}
func (t Template) ChinaGeositeRuleSetList(metadata M.Metadata) []string {
return common.Map(t.ChinaGeositeList(metadata), func(it string) string {
return "geosite-" + it
})
}
type ExtraGroup struct { type ExtraGroup struct {
Tag string `json:"tag,omitempty"` Tag string `json:"tag,omitempty"`
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`

View File

@ -128,10 +128,7 @@ func (t *Template) renderDNS(metadata M.Metadata, options *option.Options) error
{ {
Type: C.RuleTypeDefault, Type: C.RuleTypeDefault,
DefaultOptions: option.DefaultDNSRule{ DefaultOptions: option.DefaultDNSRule{
Geosite: []string{ Geosite: t.ChinaGeositeList(metadata),
"cn",
"category-companies@cn",
},
}, },
}, },
}, },
@ -154,10 +151,7 @@ func (t *Template) renderDNS(metadata M.Metadata, options *option.Options) error
{ {
Type: C.RuleTypeDefault, Type: C.RuleTypeDefault,
DefaultOptions: option.DefaultDNSRule{ DefaultOptions: option.DefaultDNSRule{
RuleSet: []string{ RuleSet: t.ChinaGeositeRuleSetList(metadata),
"geosite-cn",
"geosite-category-companies@cn",
},
DomainSuffix: []string{"download.jetbrains.com"}, DomainSuffix: []string{"download.jetbrains.com"},
}, },
}, },

View File

@ -56,7 +56,6 @@ func (t *Template) renderGeoResources(metadata M.Metadata, options *option.Optio
downloadURL = "https://raw.githubusercontent.com/" downloadURL = "https://raw.githubusercontent.com/"
branchSplit = "/" branchSplit = "/"
} }
options.Route.RuleSet = []option.RuleSet{ options.Route.RuleSet = []option.RuleSet{
{ {
Type: C.RuleSetTypeRemote, Type: C.RuleSetTypeRemote,
@ -95,5 +94,16 @@ func (t *Template) renderGeoResources(metadata M.Metadata, options *option.Optio
}, },
}, },
} }
if metadata.Platform.IsApple() {
options.Route.RuleSet = append(options.Route.RuleSet, option.RuleSet{
Type: C.RuleSetTypeRemote,
Tag: "geosite-apple-update",
Format: C.RuleSetFormatBinary,
RemoteOptions: option.RemoteRuleSet{
URL: downloadURL + "SagerNet/sing-geosite" + branchSplit + "rule-set/geosite-apple-update.srs",
DownloadDetour: downloadDetour,
},
})
}
} }
} }

View File

@ -136,7 +136,7 @@ func (t *Template) renderRoute(metadata M.Metadata, options *option.Options) err
Type: C.RuleTypeDefault, Type: C.RuleTypeDefault,
DefaultOptions: option.DefaultRule{ DefaultOptions: option.DefaultRule{
GeoIP: []string{"cn"}, GeoIP: []string{"cn"},
Geosite: []string{"cn", "category-companies@cn"}, Geosite: t.ChinaGeositeList(metadata),
Domain: []string{"download.jetbrains.com"}, Domain: []string{"download.jetbrains.com"},
}, },
}, },
@ -160,7 +160,7 @@ func (t *Template) renderRoute(metadata M.Metadata, options *option.Options) err
{ {
Type: C.RuleTypeDefault, Type: C.RuleTypeDefault,
DefaultOptions: option.DefaultRule{ DefaultOptions: option.DefaultRule{
RuleSet: []string{"geoip-cn", "geosite-cn", "geosite-category-companies@cn"}, RuleSet: append([]string{"geoip-cn"}, t.ChinaGeositeRuleSetList(metadata)...),
Domain: []string{"download.jetbrains.com"}, Domain: []string{"download.jetbrains.com"},
}, },
}, },