Automated testing takes a long time. If enabled, the task will run in the background; otherwise, it will run on the current page.

https://github.com/2dust/v2rayNG/issues/5999
This commit is contained in:
2dust committed 2026-08-02 14:42:00 +08:00
1 parent c8f78621bf
commit a899d7f444
4 files changed
+47 -3

No files matched your search

@@ -7,14 +7,19 @@ import com.v2ray.ang.dto.SubscriptionUpdateMessage
import com.v2ray.ang.dto.entities.SubscriptionCache
import com.v2ray.ang.dto.entities.SubscriptionItem
import com.v2ray.ang.extension.moveItem
import com.v2ray.ang.handler.AngConfigManager
import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.handler.SettingsChangeManager
import com.v2ray.ang.handler.SettingsManager
import com.v2ray.ang.helper.MessageHelper
import com.v2ray.ang.ui.base.BaseViewModel
import com.v2ray.ang.util.LogUtil
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.withContext
class SubscriptionsViewModel(application: Application) : BaseViewModel(application) {
private val subscriptions: MutableList<SubscriptionCache> =
@@ -59,6 +64,45 @@ class SubscriptionsViewModel(application: Application) : BaseViewModel(applicati
}
fun updateSubscriptions() {
val updateSubscription = MmkvManager.decodeSettingsBool(AppConfig.PREF_UPDATE_SUBSCRIPTION, false)
val autoTestAfterUpdateSubscription = MmkvManager.decodeSettingsBool(AppConfig.PREF_AUTO_TEST_AFTER_UPDATE_SUBSCRIPTION, false)
when {
// If auto test is enabled, trigger background service for long-running task
autoTestAfterUpdateSubscription -> updateSubscriptionsMore()
// If only update is enabled, perform local update with UI loading state
updateSubscription -> updateSubscriptionsOnly()
}
}
fun updateSubscriptionsOnly() {
launchLoading {
try {
val result = withContext(Dispatchers.IO) {
AngConfigManager.updateConfigViaSubAll()
}
when {
result.successCount + result.failureCount + result.skipCount == 0 ->
toast(R.string.title_update_subscription_no_subscription)
result.successCount > 0 && result.failureCount + result.skipCount == 0 ->
toast(getString(R.string.title_update_config_count, result.configCount))
else ->
toast(getString(R.string.title_update_subscription_result, result.configCount, result.successCount, result.failureCount, result.skipCount))
}
reload()
} catch (cancelled: CancellationException) {
throw cancelled
} catch (e: Exception) {
LogUtil.e(AppConfig.TAG, "Subscription update failed", e)
toastError(R.string.toast_failure)
}
}
}
fun updateSubscriptionsMore() {
SettingsChangeManager.makeSetupGroupTab()
val subIds = MmkvManager.decodeSubscriptions()
.filter { it.subscription.enabled && it.subscription.url.isNotEmpty() }
@@ -171,7 +171,7 @@
<string name="subscription_updater_job_tips">任务将在后台运行,在通知中会显示进度信息</string>
<string name="title_pref_auto_test_after_update_subscription">更新订阅后自动测试</string>
<string name="summary_pref_auto_test_after_update_subscription">自动测试需要比较长的时间,请耐心等待</string>
<string name="summary_pref_auto_test_after_update_subscription">自动测试需要比较长的时间,开启后任务将在后台运行;不开启则在当前页面运行</string>
<string name="title_pref_auto_remove_invalid_after_test">测试后自动删除无效配置</string>
<string name="summary_pref_auto_remove_invalid_after_test">测试结果可能不准确且已删除的配置无法恢复</string>
<string name="title_pref_auto_sort_after_test">测试后自动排序</string>
@@ -170,7 +170,7 @@
<string name="subscription_updater_job_tips">任務將在背景運行,在通知中會顯示進度資訊</string>
<string name="title_pref_auto_test_after_update_subscription">更新訂閱後自動測試</string>
<string name="summary_pref_auto_test_after_update_subscription">自動測試需要比較長的時間,請耐心等待</string>
<string name="summary_pref_auto_test_after_update_subscription">自動測試需要較長的時間,開啟後任務將在後台運行;不開啟則在目前頁面運行</string>
<string name="title_pref_auto_remove_invalid_after_test">測試後自動刪除無效配置</string>
<string name="summary_pref_auto_remove_invalid_after_test">測試結果可能不準確且已刪除的配置無法復原</string>
<string name="title_pref_auto_sort_after_test">測試後自動排序</string>
+1 -1
View File
@@ -176,7 +176,7 @@
<string name="subscription_updater_job_tips">The task will run in the background, and progress information will be displayed in the notification.</string>
<string name="title_pref_auto_test_after_update_subscription">Auto test after updating subscription</string>
<string name="summary_pref_auto_test_after_update_subscription">Automated testing takes a relatively long time, please be patient.</string>
<string name="summary_pref_auto_test_after_update_subscription">Automated testing takes a long time. If enabled, the task will run in the background; otherwise, it will run on the current page.</string>
<string name="title_pref_auto_remove_invalid_after_test">Auto delete invalid config after testing</string>
<string name="summary_pref_auto_remove_invalid_after_test">Test results may not be accurate; deleted config cannot be recovered.</string>
<string name="title_pref_auto_sort_after_test">Auto sort after testing</string>