diff --git a/core/src/main/golang/native/tunnel/proxies.go b/core/src/main/golang/native/tunnel/proxies.go index 3357d5046e..f026525f98 100644 --- a/core/src/main/golang/native/tunnel/proxies.go +++ b/core/src/main/golang/native/tunnel/proxies.go @@ -27,6 +27,7 @@ type Proxy struct { Subtitle string `json:"subtitle"` Type string `json:"type"` Delay int `json:"delay"` + IsGroup bool `json:"isGroup"` } type ProxyGroup struct { @@ -171,9 +172,10 @@ func convertProxies(proxies []C.Proxy, uiSubtitlePattern *regexp2.Regexp) []*Pro name := p.Name() title := name subtitle := p.Type().String() + _, isGroup := p.Adapter().(outboundgroup.ProxyGroup) if uiSubtitlePattern != nil { - if _, ok := p.Adapter().(outboundgroup.ProxyGroup); !ok { + if !isGroup { runes := []rune(name) match, err := uiSubtitlePattern.FindRunesMatch(runes) if err == nil && match != nil { @@ -196,6 +198,7 @@ func convertProxies(proxies []C.Proxy, uiSubtitlePattern *regexp2.Regexp) []*Pro Subtitle: strings.TrimSpace(subtitle), Type: p.Type().String(), Delay: int(p.LastDelayForTestUrl(testURL)), + IsGroup: isGroup, }) } return result @@ -209,9 +212,10 @@ func collectProviders(providers []provider.ProxyProvider, uiSubtitlePattern *reg name := px.Name() title := name subtitle := px.Type().String() + _, isGroup := px.Adapter().(outboundgroup.ProxyGroup) if uiSubtitlePattern != nil { - if _, ok := px.Adapter().(outboundgroup.ProxyGroup); !ok { + if !isGroup { runes := []rune(name) match, err := uiSubtitlePattern.FindRunesMatch(runes) if err == nil && match != nil { @@ -235,6 +239,7 @@ func collectProviders(providers []provider.ProxyProvider, uiSubtitlePattern *reg Subtitle: strings.TrimSpace(subtitle), Type: px.Type().String(), Delay: int(px.LastDelayForTestUrl(testURL)), + IsGroup: isGroup, }) } } diff --git a/core/src/main/kotlin/com/github/kr328/clash/core/model/Proxy.kt b/core/src/main/kotlin/com/github/kr328/clash/core/model/Proxy.kt index e9b03b6b30..d951866438 100644 --- a/core/src/main/kotlin/com/github/kr328/clash/core/model/Proxy.kt +++ b/core/src/main/kotlin/com/github/kr328/clash/core/model/Proxy.kt @@ -1,6 +1,7 @@ package com.github.kr328.clash.core.model import android.os.Parcelable +import kotlin.jvm.JvmInline import kotlinx.parcelize.Parcelize import kotlinx.serialization.Serializable @@ -12,37 +13,16 @@ data class Proxy( val subtitle: String, val type: Type, val delay: Int, + val isGroup: Boolean, ) : Parcelable { - enum class Type(val group: Boolean) { - Direct(false), - Reject(false), - RejectDrop(false), - Compatible(false), - Pass(false), - Shadowsocks(false), - ShadowsocksR(false), - Snell(false), - Socks5(false), - Http(false), - Vmess(false), - Vless(false), - Trojan(false), - Hysteria(false), - Hysteria2(false), - Tuic(false), - WireGuard(false), - Dns(false), - Ssh(false), - Mieru(false), - AnyTLS(false), - Sudoku(false), - Masque(false), - TrustTunnel(false), - Relay(true), - Selector(true), - Fallback(true), - URLTest(true), - LoadBalance(true), - Unknown(false), + @JvmInline + @Serializable + @Parcelize + value class Type(val name: String) : Parcelable { + companion object { + val Selector: Type = Type("Selector") + val URLTest: Type = Type("URLTest") + val Unknown: Type = Type("Unknown") + } } } diff --git a/ui/proxy/src/androidMain/kotlin/com/github/kr328/clash/proxy/ui/ProxyScreen.kt b/ui/proxy/src/androidMain/kotlin/com/github/kr328/clash/proxy/ui/ProxyScreen.kt index 2902d631ce..a89c007998 100644 --- a/ui/proxy/src/androidMain/kotlin/com/github/kr328/clash/proxy/ui/ProxyScreen.kt +++ b/ui/proxy/src/androidMain/kotlin/com/github/kr328/clash/proxy/ui/ProxyScreen.kt @@ -649,6 +649,7 @@ private fun ProxyContentPreview() { subtitle = "", type = Proxy.Type.URLTest, delay = 48, + isGroup = true, ), linkIndex = 1, ), @@ -658,8 +659,9 @@ private fun ProxyContentPreview() { name = "hk-01", title = "Hong Kong 01", subtitle = "BGP | 1.2x", - type = Proxy.Type.Shadowsocks, + type = Proxy.Type("Shadowsocks"), delay = 62, + isGroup = false, ), linkIndex = -1, ), diff --git a/ui/proxy/src/androidMain/kotlin/com/github/kr328/clash/proxy/vm/ProxyViewModel.kt b/ui/proxy/src/androidMain/kotlin/com/github/kr328/clash/proxy/vm/ProxyViewModel.kt index bad929819b..3bc6b47b9b 100644 --- a/ui/proxy/src/androidMain/kotlin/com/github/kr328/clash/proxy/vm/ProxyViewModel.kt +++ b/ui/proxy/src/androidMain/kotlin/com/github/kr328/clash/proxy/vm/ProxyViewModel.kt @@ -218,7 +218,7 @@ internal class ProxyViewModel(private val uiStore: UiStore) : group.proxies.map { proxy -> UiState.ProxyItemSource( proxy = proxy, - linkIndex = if (proxy.type.group) nameIndexMap[proxy.name] ?: -1 else -1, + linkIndex = if (proxy.isGroup) nameIndexMap[proxy.name] ?: -1 else -1, ) } } @@ -287,9 +287,9 @@ internal class ProxyViewModel(private val uiStore: UiStore) : unselectedBackground } val controls = if (selected) selectedControl else unselectedControl - val title = if (proxy.type.group) proxy.name else proxy.title + val title = if (proxy.isGroup) proxy.name else proxy.title val subtitle = - if (proxy.type.group) { + if (proxy.isGroup) { if (linkNow == null) { proxy.type.name } else {