Skip to content

Commit

Permalink
Test connection after updating subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Oct 28, 2024
1 parent 9caafc4 commit 23264d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 5 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 @@ -342,11 +342,13 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
}

R.id.ping_all -> {
toast(R.string.connection_test_testing)
mainViewModel.testAllTcping()
true
}

R.id.real_ping_all -> {
toast(R.string.connection_test_testing)
mainViewModel.testAllRealPing()
true
}
Expand Down Expand Up @@ -604,8 +606,10 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
delay(500L)
launch(Dispatchers.Main) {
if (count > 0) {
toast(R.string.toast_success)
//toast(R.string.toast_success)
toast(R.string.connection_test_testing)
mainViewModel.reloadServerList()
mainViewModel.testAllRealPing()
} else {
toast(R.string.toast_failure)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.v2ray.ang.dto.V2rayConfig
import com.v2ray.ang.extension.serializable
import com.v2ray.ang.extension.toast
import com.v2ray.ang.util.AngConfigManager
import com.v2ray.ang.util.AngConfigManager.updateConfigViaSub
import com.v2ray.ang.util.JsonUtil
import com.v2ray.ang.util.MessageUtil
import com.v2ray.ang.util.MmkvManager
Expand Down Expand Up @@ -157,7 +156,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
return AngConfigManager.updateConfigViaSubAll()
} else {
val subItem = MmkvManager.decodeSubscription(subscriptionId) ?: return 0
return updateConfigViaSub(Pair(subscriptionId, subItem))
return AngConfigManager.updateConfigViaSub(Pair(subscriptionId, subItem))
}
}

Expand All @@ -181,10 +180,10 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
tcpingTestScope.coroutineContext[Job]?.cancelChildren()
SpeedtestUtil.closeAllTcpSockets()
MmkvManager.clearAllTestDelayResults(serversCache.map { it.guid }.toList())
updateListAction.value = -1 // update all
//updateListAction.value = -1 // update all

getApplication<AngApplication>().toast(R.string.connection_test_testing)
for (item in serversCache) {
val serversCopy = serversCache.toList() // Create a copy of the list
for (item in serversCopy) {
item.profile.let { outbound ->
val serverAddress = outbound.server
val serverPort = outbound.serverPort
Expand All @@ -207,8 +206,6 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
updateListAction.value = -1 // update all

val serversCopy = serversCache.toList() // Create a copy of the list

getApplication<AngApplication>().toast(R.string.connection_test_testing)
viewModelScope.launch(Dispatchers.Default) { // without Dispatchers.Default viewModelScope will launch in main thread
for (item in serversCopy) {
MessageUtil.sendMsg2TestService(getApplication(), AppConfig.MSG_MEASURE_CONFIG, item.guid)
Expand Down

0 comments on commit 23264d7

Please sign in to comment.