Skip to content

Commit

Permalink
Added attempt to update subscription via proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed May 5, 2024
1 parent e053db3 commit a1d68fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 13 additions & 1 deletion V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,22 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
}
Log.d(ANG_PACKAGE, url)
lifecycleScope.launch(Dispatchers.IO) {
val configText = try {
var configText = try {
Utils.getUrlContentWithCustomUserAgent(url)
} catch (e: Exception) {
e.printStackTrace()
""
}
if(configText.isEmpty()) {
configText = try {
val httpPort = Utils.parseInt(settingsStorage?.decodeString(AppConfig.PREF_HTTP_PORT), AppConfig.PORT_HTTP.toInt())
Utils.getUrlContentWithCustomUserAgent(url, httpPort)
} catch (e: Exception) {
e.printStackTrace()
""
}
}
if(configText.isEmpty()) {
launch(Dispatchers.Main) {
toast("\"" + it.second.remarks + "\" " + getString(R.string.toast_failure))
}
Expand Down
13 changes: 11 additions & 2 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,18 @@ object Utils {
}

@Throws(IOException::class)
fun getUrlContentWithCustomUserAgent(urlStr: String?): String {
fun getUrlContentWithCustomUserAgent(urlStr: String?, httpPort: Int = 0): String {
val url = URL(urlStr)
val conn = url.openConnection()
val conn = if (httpPort == 0) {
url.openConnection()
} else {
url.openConnection(
Proxy(
Proxy.Type.HTTP,
InetSocketAddress("127.0.0.1", httpPort)
)
)
}
conn.setRequestProperty("Connection", "close")
conn.setRequestProperty("User-agent", "v2rayNG/${BuildConfig.VERSION_NAME}")
url.userInfo?.let {
Expand Down

0 comments on commit a1d68fc

Please sign in to comment.