Skip to content

Commit

Permalink
Add apple-update rule for apple clients
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Dec 30, 2023
1 parent 22d9c49 commit 2a3dabd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
18 changes: 17 additions & 1 deletion option/template.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package option

import (
M "github.com/sagernet/serenity/common/metadata"
"github.com/sagernet/serenity/common/semver"
"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"
)

Expand Down Expand Up @@ -67,6 +69,20 @@ func (t Template) DisableIPv6() bool {
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 {
Tag string `json:"tag,omitempty"`
Type string `json:"type,omitempty"`
Expand Down
10 changes: 2 additions & 8 deletions template/render_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ func (t *Template) renderDNS(metadata M.Metadata, options *option.Options) error
{
Type: C.RuleTypeDefault,
DefaultOptions: option.DefaultDNSRule{
Geosite: []string{
"cn",
"category-companies@cn",
},
Geosite: t.ChinaGeositeList(metadata),
},
},
},
Expand All @@ -154,10 +151,7 @@ func (t *Template) renderDNS(metadata M.Metadata, options *option.Options) error
{
Type: C.RuleTypeDefault,
DefaultOptions: option.DefaultDNSRule{
RuleSet: []string{
"geosite-cn",
"geosite-category-companies@cn",
},
RuleSet: t.ChinaGeositeRuleSetList(metadata),
DomainSuffix: []string{"download.jetbrains.com"},
},
},
Expand Down
12 changes: 11 additions & 1 deletion template/render_geo_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (t *Template) renderGeoResources(metadata M.Metadata, options *option.Optio
downloadURL = "https://raw.githubusercontent.com/"
branchSplit = "/"
}

options.Route.RuleSet = []option.RuleSet{
{
Type: C.RuleSetTypeRemote,
Expand Down Expand Up @@ -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,
},
})
}
}
}
4 changes: 2 additions & 2 deletions template/render_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (t *Template) renderRoute(metadata M.Metadata, options *option.Options) err
Type: C.RuleTypeDefault,
DefaultOptions: option.DefaultRule{
GeoIP: []string{"cn"},
Geosite: []string{"cn", "category-companies@cn"},
Geosite: t.ChinaGeositeList(metadata),
Domain: []string{"download.jetbrains.com"},
},
},
Expand All @@ -160,7 +160,7 @@ func (t *Template) renderRoute(metadata M.Metadata, options *option.Options) err
{
Type: C.RuleTypeDefault,
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"},
},
},
Expand Down

0 comments on commit 2a3dabd

Please sign in to comment.