Skip to content

Commit

Permalink
style: Make the code more beautiful
Browse files Browse the repository at this point in the history
  • Loading branch information
purofle committed Nov 1, 2023
1 parent f839b26 commit 5370f81
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class StandardV2RayBean extends AbstractBean {

//////// End of VMess & VLESS ////////

// "V2Ray Transport" tcp/http/ws/quic/grpc/httpupgrade
// "V2Ray Transport" tcp/http/ws/quic/grpc/httpUpgrade
public String type;

public String host;
Expand Down Expand Up @@ -133,7 +133,7 @@ public void serialize(ByteBufferOutput output) {
case "grpc": {
output.writeString(path);
}
case "httpupgrade": {
case "httpUpgrade": {
output.writeString(host);
output.writeString(path);

Expand Down Expand Up @@ -185,7 +185,7 @@ public void deserialize(ByteBufferInput input) {
case "grpc": {
path = input.readString();
}
case "httpupgrade": {
case "httpUpgrade": {
host = input.readString();
path = input.readString();
}
Expand Down
24 changes: 18 additions & 6 deletions app/src/main/java/io/nekohasekai/sagernet/fmt/v2ray/V2RayFmt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ import com.google.gson.Gson
import io.nekohasekai.sagernet.fmt.http.HttpBean
import io.nekohasekai.sagernet.fmt.trojan.TrojanBean
import io.nekohasekai.sagernet.ktx.*
import moe.matsuri.nb4a.SingBoxOptions.*
import moe.matsuri.nb4a.SingBoxOptions.Outbound
import moe.matsuri.nb4a.SingBoxOptions.OutboundRealityOptions
import moe.matsuri.nb4a.SingBoxOptions.OutboundTLSOptions
import moe.matsuri.nb4a.SingBoxOptions.OutboundUTLSOptions
import moe.matsuri.nb4a.SingBoxOptions.Outbound_HTTPOptions
import moe.matsuri.nb4a.SingBoxOptions.Outbound_TrojanOptions
import moe.matsuri.nb4a.SingBoxOptions.Outbound_VLESSOptions
import moe.matsuri.nb4a.SingBoxOptions.Outbound_VMessOptions
import moe.matsuri.nb4a.SingBoxOptions.V2RayTransportOptions
import moe.matsuri.nb4a.SingBoxOptions.V2RayTransportOptions_GRPCOptions
import moe.matsuri.nb4a.SingBoxOptions.V2RayTransportOptions_HTTPOptions
import moe.matsuri.nb4a.SingBoxOptions.V2RayTransportOptions_HTTPUpgradeOptions
import moe.matsuri.nb4a.SingBoxOptions.V2RayTransportOptions_WebsocketOptions
import moe.matsuri.nb4a.utils.NGUtil
import moe.matsuri.nb4a.utils.listByLineOrComma
import okhttp3.HttpUrl
Expand Down Expand Up @@ -117,7 +129,7 @@ fun parseV2Ray(link: String): StandardV2RayBean {
}
}

"httpupgrade" -> {
"httpUpgrade" -> {
url.queryParameter("path")?.let {
bean.path = it
}
Expand Down Expand Up @@ -225,7 +237,7 @@ fun StandardV2RayBean.parseDuckSoft(url: HttpUrl) {
}
}

"httpupgrade" -> {
"httpUpgrade" -> {
url.queryParameter("host")?.let {
host = it
}
Expand Down Expand Up @@ -454,7 +466,7 @@ fun StandardV2RayBean.toUriVMessVLESSTrojan(isTrojan: Boolean): String {

when (type) {
"tcp" -> {}
"ws", "http", "httpupgrade" -> {
"ws", "http", "httpUpgrade" -> {
if (host.isNotBlank()) {
builder.addQueryParameter("host", host)
}
Expand Down Expand Up @@ -583,9 +595,9 @@ fun buildSingBoxOutboundStreamSettings(bean: StandardV2RayBean): V2RayTransportO
}
}

"httpupgrade" -> {
"httpUpgrade" -> {
return V2RayTransportOptions_HTTPUpgradeOptions().apply {
type = "httpupgrade"
type = "httpUpgrade"
host = bean.host
path = bean.path
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@ abstract class StandardV2RaySettingsActivity : ProfileSettingsActivity<StandardV
path.preference.isVisible = true
wsCategory.isVisible = true
}

"grpc" -> {
path.preference.setTitle(R.string.grpc_service_name)
path.preference.isVisible = true
}
"httpupgrade" -> {
host.preference.setTitle("HTTPUpgrade Host")
path.preference.setTitle("HTTPUpgrade Path")

"httpUpgrade" -> {
host.preference.setTitle(R.string.http_upgrade_host)
path.preference.setTitle(R.string.http_upgrade_path)
host.preference.isVisible = true
path.preference.isVisible = true
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -485,4 +485,6 @@
<string name="dynamic_record_sizing_disabled">禁用TLS记录的自适应调整大小</string>
<string name="dynamic_record_sizing_sum">如果启用,将始终使用最大可能的TLS记录大小。当禁用时,TLS记录的大小可能会进行调整以尝试提高延迟。</string>
<string name="ech_config">ECH 配置</string>
<string name="http_upgrade_host">HTTPUpgrade 主机</string>
<string name="http_upgrade_path">HTTPUpgrade 端口</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
<item>http</item>
<item>quic</item>
<item>grpc</item>
<item>httpupgrade</item>
<item>httpUpgrade</item>
</string-array>

<string-array name="trojan_go_networks_entry">
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -526,5 +526,7 @@ Anyone can write advanced plugins, which can control NekoBox. please download an
<string name="dynamic_record_sizing_disabled">Disables adaptive sizing of TLS records</string>
<string name="ech_config">ECH Config</string>
<string name="dynamic_record_sizing_sum">If enable, the largest possible TLS record size is always used. When disable, the size of TLS records may be adjusted in an attempt to improve latency.</string>
<string name="http_upgrade_host">HTTPUpgrade Host</string>
<string name="http_upgrade_path">HTTPUpgrade Path</string>

</resources>

0 comments on commit 5370f81

Please sign in to comment.