Refactor Proxy.Type to value class for forward compatibility#337
Merged
Conversation
Merged
Goooler
commented
Jun 14, 2026
There was a problem hiding this comment.
Pull request overview
This pull request refactors Proxy.Type from a rigid Kotlin enum class to a @JvmInline value class wrapping a String, improving forward compatibility with upstream proxy/protocol types serialized from the native Go layer without causing SerializationException crashes. To preserve the UI’s ability to distinguish proxy groups from leaf proxies after removing Type.group, it also introduces an explicit isGroup boolean surfaced from the Go layer and consumed by the proxy UI.
Changes:
- Refactor
core.model.Proxy.Typeto an inline, serializable, parcelable value class and introduceProxy.isGroup. - Update proxy UI/view-model logic to use
proxy.isGroupinstead ofproxy.type.group. - Extend native Go proxy JSON payloads to include
isGroupfor each proxy entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ui/proxy/src/androidMain/kotlin/com/github/kr328/clash/proxy/vm/ProxyViewModel.kt | Switch group-detection logic from type.group to isGroup for linking and display. |
| ui/proxy/src/androidMain/kotlin/com/github/kr328/clash/proxy/ui/ProxyScreen.kt | Update preview data to include isGroup and construct Proxy.Type via string where needed. |
| core/src/main/kotlin/com/github/kr328/clash/core/model/Proxy.kt | Convert Proxy.Type to an inline value class and add isGroup to the model. |
| core/src/main/golang/native/tunnel/proxies.go | Add isGroup to the JSON model and populate it via adapter type assertions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why we must make this change
Historically,
Proxy.Typewas defined as a rigidenum class. Since the native Go layer serializes proxy types as raw string primitives (e.g.,"ss","vmess","hysteria2"), the app would throw aSerializationExceptionand crash if it encountered a new or custom protocol type added upstream in Mihomo that Kotlin wasn't yet aware of.While switching to a plain
Stringwould avoid deserialization failures, it compromises type safety and code readability. RefactoringProxy.Typeto a@JvmInline value classwrapping aStringachieves the best of both worlds:Typenested underProxyand exposing companion constants (likeProxy.Type.SelectorandProxy.Type.URLTest), we minimize code modifications elsewhere and retain autocomplete support.Ports MetaCubeX@68c4be2.