mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 01:51:29 +00:00
Fixed order for Clash modes
This commit is contained in:
parent
da9e22b4e6
commit
d7160c19cf
|
@ -3,6 +3,7 @@ package experimental
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/sagernet/sing-box/adapter"
|
"github.com/sagernet/sing-box/adapter"
|
||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
|
@ -27,11 +28,26 @@ func NewClashServer(ctx context.Context, router adapter.Router, logFactory log.O
|
||||||
}
|
}
|
||||||
|
|
||||||
func CalculateClashModeList(options option.Options) []string {
|
func CalculateClashModeList(options option.Options) []string {
|
||||||
var clashMode []string
|
var clashModes []string
|
||||||
clashMode = append(clashMode, extraClashModeFromRule(common.PtrValueOrDefault(options.Route).Rules)...)
|
clashModes = append(clashModes, extraClashModeFromRule(common.PtrValueOrDefault(options.Route).Rules)...)
|
||||||
clashMode = append(clashMode, extraClashModeFromDNSRule(common.PtrValueOrDefault(options.DNS).Rules)...)
|
clashModes = append(clashModes, extraClashModeFromDNSRule(common.PtrValueOrDefault(options.DNS).Rules)...)
|
||||||
clashMode = common.FilterNotDefault(common.Uniq(clashMode))
|
clashModes = common.FilterNotDefault(common.Uniq(clashModes))
|
||||||
return clashMode
|
predefinedOrder := []string{
|
||||||
|
"Rule", "Global", "Direct",
|
||||||
|
}
|
||||||
|
var newClashModes []string
|
||||||
|
for _, mode := range clashModes {
|
||||||
|
if !common.Contains(predefinedOrder, mode) {
|
||||||
|
newClashModes = append(newClashModes, mode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(newClashModes)
|
||||||
|
for _, mode := range predefinedOrder {
|
||||||
|
if common.Contains(clashModes, mode) {
|
||||||
|
newClashModes = append(newClashModes, mode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newClashModes
|
||||||
}
|
}
|
||||||
|
|
||||||
func extraClashModeFromRule(rules []option.Rule) []string {
|
func extraClashModeFromRule(rules []option.Rule) []string {
|
||||||
|
|
Loading…
Reference in a new issue