Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jan 19, 2024
1 parent 01e0a65 commit a18b8f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
22 changes: 13 additions & 9 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/extension/_Ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ val Context.v2RayApplication: AngApplication
get() = applicationContext as AngApplication

fun Context.toast(message: Int): Toast = ToastCompat
.makeText(this, message, Toast.LENGTH_SHORT)
.apply {
show()
}
.makeText(this, message, Toast.LENGTH_SHORT)
.apply {
show()
}

fun Context.toast(message: CharSequence): Toast = ToastCompat
.makeText(this, message, Toast.LENGTH_SHORT)
.apply {
show()
}
.makeText(this, message, Toast.LENGTH_SHORT)
.apply {
show()
}

fun JSONObject.putOpt(pair: Pair<String, Any>) = putOpt(pair.first, pair.second)
fun JSONObject.putOpt(pairs: Map<String, Any>) = pairs.forEach { putOpt(it.key to it.value) }
Expand Down Expand Up @@ -77,4 +77,8 @@ val URLConnection.responseLength: Long
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) contentLengthLong else contentLength.toLong()

val URI.idnHost: String
get() = (host!!).replace("[", "").replace("]", "")
get() = (host!!).replace("[", "").replace("]", "")

fun String.removeWhiteSpace(): String {
return this.replace(" ", "")
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.v2ray.ang.dto.ServerConfig
import com.v2ray.ang.dto.V2rayConfig
import com.v2ray.ang.dto.V2rayConfig.Companion.DEFAULT_PORT
import com.v2ray.ang.dto.V2rayConfig.Companion.TLS
import com.v2ray.ang.extension.removeWhiteSpace
import com.v2ray.ang.extension.toast
import com.v2ray.ang.util.MmkvManager
import com.v2ray.ang.util.MmkvManager.ID_MAIN
Expand Down Expand Up @@ -476,7 +477,7 @@ class ServerActivity : BaseActivity() {
} else {
wireguard.reserved = null
}
wireguard.address = listOf(et_local_address?.text.toString().trim())
wireguard.address = et_local_address?.text.toString().removeWhiteSpace().split(",")
wireguard.mtu = Utils.parseInt(et_local_mtu?.text.toString())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.v2ray.ang.util.MmkvManager.KEY_SELECTED_SERVER
import java.net.URI
import java.util.*
import com.v2ray.ang.extension.idnHost
import com.v2ray.ang.extension.removeWhiteSpace
import com.v2ray.ang.extension.toast

object AngConfigManager {
Expand Down Expand Up @@ -446,13 +447,13 @@ object AngConfigManager {
config.outboundBean?.settings?.let { wireguard ->
wireguard.secretKey = uri.userInfo
wireguard.address =
(queryParam["address"] ?: WIREGUARD_LOCAL_ADDRESS_V4).replace(" ", "")
(queryParam["address"] ?: WIREGUARD_LOCAL_ADDRESS_V4).removeWhiteSpace()
.split(",")
wireguard.peers?.get(0)?.publicKey = queryParam["publickey"] ?: ""
wireguard.peers?.get(0)?.endpoint = "${uri.idnHost}:${uri.port}"
wireguard.mtu = Utils.parseInt(queryParam["mtu"] ?: WIREGUARD_LOCAL_MTU)
wireguard.reserved =
(queryParam["reserved"] ?: "0,0,0").replace(" ", "").split(",")
(queryParam["reserved"] ?: "0,0,0").removeWhiteSpace().split(",")
.map { it.toInt() }
}
}
Expand Down

0 comments on commit a18b8f4

Please sign in to comment.