Skip to content

Commit 68c4be2

Browse files
committed
don't use enum class for Proxy.Type
1 parent 9bfdd3a commit 68c4be2

8 files changed

Lines changed: 16 additions & 53 deletions

File tree

app/src/main/java/com/github/kr328/clash/ProxyActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ProxyActivity : BaseActivity<ProxyDesign>() {
7575
design.updateGroup(
7676
it.index,
7777
group.proxies,
78-
group.type == Proxy.Type.Selector,
78+
group.type == "Selector",
7979
state,
8080
unorderedStates
8181
)

core/src/main/golang/.idea/codeStyles/Project.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/main/golang/native/tunnel/proxies.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Proxy struct {
2727
Subtitle string `json:"subtitle"`
2828
Type string `json:"type"`
2929
Delay int `json:"delay"`
30+
IsGroup bool `json:"isGroup"`
3031
}
3132

3233
type ProxyGroup struct {
@@ -189,13 +190,15 @@ func convertProxies(proxies []C.Proxy, uiSubtitlePattern *regexp2.Regexp) []*Pro
189190
break
190191
}
191192
}
193+
_, isGroup := p.Adapter().(outboundgroup.ProxyGroup)
192194

193195
result = append(result, &Proxy{
194196
Name: name,
195197
Title: strings.TrimSpace(title),
196198
Subtitle: strings.TrimSpace(subtitle),
197199
Type: p.Type().String(),
198200
Delay: int(p.LastDelayForTestUrl(testURL)),
201+
IsGroup: isGroup,
199202
})
200203
}
201204
return result
@@ -228,13 +231,15 @@ func collectProviders(providers []provider.ProxyProvider, uiSubtitlePattern *reg
228231
break
229232
}
230233
}
234+
_, isGroup := px.Adapter().(outboundgroup.ProxyGroup)
231235

232236
result = append(result, &Proxy{
233237
Name: name,
234238
Title: strings.TrimSpace(title),
235239
Subtitle: strings.TrimSpace(subtitle),
236240
Type: px.Type().String(),
237241
Delay: int(px.LastDelayForTestUrl(testURL)),
242+
IsGroup: isGroup,
238243
})
239244
}
240245
}

core/src/main/java/com/github/kr328/clash/core/Clash.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ object Clash {
116116
fun queryGroup(name: String, sort: ProxySort): ProxyGroup {
117117
return Bridge.nativeQueryGroup(name, sort.name)
118118
?.let { Json.Default.decodeFromString(ProxyGroup.serializer(), it) }
119-
?: ProxyGroup(Proxy.Type.Unknown, emptyList(), "")
119+
?: ProxyGroup("Unknown", emptyList(), "")
120120
}
121121

122122
fun healthCheck(name: String): CompletableDeferred<Unit> {

core/src/main/java/com/github/kr328/clash/core/model/Proxy.kt

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,51 +10,10 @@ data class Proxy(
1010
val name: String,
1111
val title: String,
1212
val subtitle: String,
13-
val type: Type,
13+
val type: String,
1414
val delay: Int,
15+
var isGroup: Boolean,
1516
) : Parcelable {
16-
@Suppress("unused")
17-
enum class Type(val group: Boolean) {
18-
Direct(false),
19-
Reject(false),
20-
RejectDrop(false),
21-
Compatible(false),
22-
Pass(false),
23-
PassRule(false),
24-
25-
Shadowsocks(false),
26-
ShadowsocksR(false),
27-
Snell(false),
28-
Socks5(false),
29-
Http(false),
30-
Vmess(false),
31-
Vless(false),
32-
Trojan(false),
33-
Hysteria(false),
34-
Hysteria2(false),
35-
Tuic(false),
36-
WireGuard(false),
37-
Dns(false),
38-
Ssh(false),
39-
Mieru(false),
40-
AnyTLS(false),
41-
Sudoku(false),
42-
Masque(false),
43-
TrustTunnel(false),
44-
OpenVPN(false),
45-
Tailscale(false),
46-
GostRelay(false),
47-
48-
49-
Relay(true),
50-
Selector(true),
51-
Fallback(true),
52-
URLTest(true),
53-
LoadBalance(true),
54-
55-
Unknown(false);
56-
}
57-
5817
override fun writeToParcel(parcel: Parcel, flags: Int) {
5918
Parcelizer.encodeToParcel(serializer(), parcel, this)
6019
}

core/src/main/java/com/github/kr328/clash/core/model/ProxyGroup.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import kotlinx.serialization.Serializable
88

99
@Serializable
1010
data class ProxyGroup(
11-
val type: Proxy.Type,
11+
val type: String,
1212
val proxies: List<Proxy>,
1313
val now: String,
1414
) : Parcelable {
@@ -35,13 +35,13 @@ data class ProxyGroup(
3535
}
3636

3737
constructor(parcel: Parcel) : this(
38-
Proxy.Type.values()[parcel.readInt()],
38+
parcel.readString()!!,
3939
SliceProxyList(parcel),
4040
parcel.readString()!!,
4141
)
4242

4343
override fun writeToParcel(parcel: Parcel, flags: Int) {
44-
parcel.writeInt(type.ordinal)
44+
parcel.writeString(type)
4545
SliceProxyList(proxies).writeToParcel(parcel, 0)
4646
parcel.writeString(now)
4747
}

design/src/main/java/com/github/kr328/clash/design/adapter/ProxyPageAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ProxyPageAdapter(
3434
) {
3535
val states = withContext(Dispatchers.Default) {
3636
proxies.map {
37-
val link = if (it.type.group) links[it.name] else null
37+
val link = if (it.isGroup) links[it.name] else null
3838

3939
ProxyViewState(config, it, parent, link)
4040
}

design/src/main/java/com/github/kr328/clash/design/component/ProxyViewState.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ class ProxyViewState(
3636
val frameTime = System.currentTimeMillis()
3737
var invalidate = false
3838

39-
if (proxy.type.group) {
39+
if (proxy.isGroup) {
4040
title = proxy.name
4141

4242
if (link == null) {
43-
subtitle = proxy.type.name
43+
subtitle = proxy.type
4444
} else {
4545
if (linkNow !== link.now) {
4646
linkNow = link.now
4747

4848
subtitle = "%s(%s)".format(
49-
proxy.type.name,
49+
proxy.type,
5050
link.now.ifEmpty { "*" }
5151
)
5252
}

0 commit comments

Comments
 (0)