Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Update subscriptions through the proxy first, then update them directly
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust authored and AnGgIt86 committed Sep 30, 2024
1 parent 8622740 commit e14646e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.neko.v2ray.AppConfig.SUBSCRIPTION_UPDATE_CHANNEL
import com.neko.v2ray.AppConfig.SUBSCRIPTION_UPDATE_CHANNEL_NAME
import com.neko.v2ray.R
import com.neko.v2ray.util.AngConfigManager
import com.neko.v2ray.util.AngConfigManager.updateConfigViaSub
import com.neko.v2ray.util.MmkvManager
import com.neko.v2ray.util.Utils

Expand All @@ -40,8 +41,8 @@ object SubscriptionUpdater {

val subs = MmkvManager.decodeSubscriptions().filter { it.second.autoUpdate }

for (i in subs) {
val subscription = i.second
for (sub in subs) {
val subItem = sub.second

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notification.setChannelId(SUBSCRIPTION_UPDATE_CHANNEL)
Expand All @@ -56,11 +57,10 @@ object SubscriptionUpdater {
notificationManager.notify(3, notification.build())
Log.d(
AppConfig.ANG_PACKAGE,
"subscription automatic update: ---${subscription.remarks}"
"subscription automatic update: ---${subItem.remarks}"
)
val configs = Utils.getUrlContentWithCustomUserAgent(subscription.url)
AngConfigManager.importBatchConfig(configs, i.first, false)
notification.setContentText("Updating ${subscription.remarks}")
updateConfigViaSub(Pair(sub.first, subItem))
notification.setContentText("Updating ${subItem.remarks}")
}
notificationManager.cancel(3)
return Result.success()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class V2RayVpnService : VpnService(), ServiceControl {
}

private fun runTun2socks() {
val socksPort = Utils.parseInt(settingsStorage?.decodeString(AppConfig.PREF_SOCKS_PORT), AppConfig.PORT_SOCKS.toInt())
val socksPort = SettingsManager.getSocksPort()
val cmd = arrayListOf(
File(applicationContext.applicationInfo.nativeLibraryDir, TUN2SOCKS).absolutePath,
"--netif-ipaddr", PRIVATE_VLAN4_ROUTER,
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/kotlin/com/neko/v2ray/ui/UserAssetActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.neko.v2ray.extension.toTrafficString
import com.neko.v2ray.extension.toast
import com.neko.v2ray.util.MmkvManager
import com.neko.v2ray.util.MmkvManager.settingsStorage
import com.neko.v2ray.util.SettingsManager
import com.neko.v2ray.util.Utils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -182,7 +183,7 @@ class UserAssetActivity : BaseActivity() {
.show()
toast(R.string.msg_downloading_content)

val httpPort = Utils.parseInt(settingsStorage?.decodeString(AppConfig.PREF_HTTP_PORT), AppConfig.PORT_HTTP.toInt())
val httpPort = SettingsManager.getHttpPort()
var assets = MmkvManager.decodeAssetUrls()
assets = addBuiltInGeoItems(assets)

Expand Down
11 changes: 4 additions & 7 deletions app/src/main/kotlin/com/neko/v2ray/util/AngConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.neko.v2ray.AppConfig
import com.neko.v2ray.AppConfig.HY2
import com.neko.v2ray.R
import com.neko.v2ray.dto.*
import com.neko.v2ray.util.MmkvManager.settingsStorage
import com.neko.v2ray.util.fmt.Hysteria2Fmt
import com.neko.v2ray.util.fmt.ShadowsocksFmt
import com.neko.v2ray.util.fmt.SocksFmt
Expand Down Expand Up @@ -373,19 +372,17 @@ object AngConfigManager {
return 0
}
Log.d(AppConfig.ANG_PACKAGE, url)

var configText = try {
Utils.getUrlContentWithCustomUserAgent(url)
val httpPort = SettingsManager.getHttpPort()
Utils.getUrlContentWithCustomUserAgent(url, 30000, httpPort)
} 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, 30000, httpPort)
Utils.getUrlContentWithCustomUserAgent(url)
} catch (e: Exception) {
e.printStackTrace()
""
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/com/neko/v2ray/util/PluginUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object PluginUtil {
if (outbound.protocol.equals(EConfigType.HYSTERIA2.name, true)) {
Log.d(packageName, "runPlugin $HYSTERIA2")

val socksPort = 100 + Utils.parseInt(settingsStorage?.decodeString(AppConfig.PREF_SOCKS_PORT), AppConfig.PORT_SOCKS.toInt())
val socksPort = 100 + SettingsManager.getSocksPort()
val hy2Config = Hysteria2Fmt.toNativeConfig(config, socksPort) ?: return

val configFile = File(context.noBackupFilesDir, "hy2_${SystemClock.elapsedRealtime()}.json")
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/kotlin/com/neko/v2ray/util/SettingsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package com.neko.v2ray.util

import android.content.Context
import android.text.TextUtils
import com.google.gson.Gson
import com.google.gson.Gsonl
import com.neko.v2ray.AppConfig
import com.neko.v2ray.dto.RulesetItem
import com.neko.v2ray.dto.ServerConfig
import com.neko.v2ray.util.MmkvManager.decodeProfileConfig
import com.neko.v2ray.util.MmkvManager.decodeServerConfig
import com.neko.v2ray.util.MmkvManager.decodeServerList
import com.neko.v2ray.util.MmkvManager.settingsStorage
import com.neko.v2ray.util.Utils.parseInt
import java.util.Collections

object SettingsManager {
Expand Down Expand Up @@ -140,4 +143,12 @@ object SettingsManager {
return null
}

fun getSocksPort(): Int {
return parseInt(settingsStorage?.decodeString(AppConfig.PREF_SOCKS_PORT), AppConfig.PORT_SOCKS.toInt())
}

fun getHttpPort(): Int {
return parseInt(settingsStorage?.decodeString(AppConfig.PREF_HTTP_PORT), AppConfig.PORT_HTTP.toInt())
}

}
12 changes: 3 additions & 9 deletions app/src/main/kotlin/com/neko/v2ray/util/V2rayConfigUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,8 @@ object V2rayConfigUtil {

private fun inbounds(v2rayConfig: V2rayConfig): Boolean {
try {
val socksPort = Utils.parseInt(
settingsStorage?.decodeString(AppConfig.PREF_SOCKS_PORT),
AppConfig.PORT_SOCKS.toInt()
)
val httpPort = Utils.parseInt(
settingsStorage?.decodeString(AppConfig.PREF_HTTP_PORT),
AppConfig.PORT_HTTP.toInt()
)
val socksPort = SettingsManager.getSocksPort()
val httpPort = SettingsManager.getHttpPort()

v2rayConfig.inbounds.forEach { curInbound ->
if (settingsStorage?.decodeBool(AppConfig.PREF_PROXY_SHARING) != true) {
Expand Down Expand Up @@ -149,7 +143,7 @@ object V2rayConfigUtil {

private fun outbounds(v2rayConfig: V2rayConfig, outbound: V2rayConfig.OutboundBean, isPlugin: Boolean): Pair<Boolean, String> {
if (isPlugin) {
val socksPort = 100 + Utils.parseInt(settingsStorage?.decodeString(AppConfig.PREF_SOCKS_PORT), AppConfig.PORT_SOCKS.toInt())
val socksPort = 100 + SettingsManager.getSocksPort()
val outboundNew = V2rayConfig.OutboundBean(
mux = null,
protocol = EConfigType.SOCKS.name.lowercase(),
Expand Down

0 comments on commit e14646e

Please sign in to comment.