add autostop on strategy testing error

This commit is contained in:
white
2025-12-08 12:07:38 +03:00
parent 87a9740aad
commit 77823252f2

View File

@@ -122,16 +122,20 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
} }
suspend fun performTest() { suspend fun performTest() {
val targets = readActiveListsLines() val targets = readActiveListsLines()
var stopTest : Boolean = false;
for (index in strategyStates.indices) { for (index in strategyStates.indices) {
val current = strategyStates[index] val current = strategyStates[index]
if (stopTest) break
strategyStates[index] = current.copy(status = StrategyTestingStatus.Testing) strategyStates[index] = current.copy(status = StrategyTestingStatus.Testing)
enableStrategy(current.path, prefs) enableStrategy(current.path, prefs)
if (prefs.getBoolean("use_module", false)) { if (prefs.getBoolean("use_module", false)) {
getStatus { if (it) stopService { error -> getStatus { if (it) stopService { error ->
_errorFlow.value = error _errorFlow.value = error
if (error.isNotEmpty()) stopTest = true
} } } }
startService { error -> startService { error ->
_errorFlow.value = error _errorFlow.value = error
if (error.isNotEmpty()) stopTest = true
} }
try { try {
val progress = countReachable(index, targets) val progress = countReachable(index, targets)
@@ -143,6 +147,7 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
} finally { } finally {
stopService { error -> stopService { error ->
_errorFlow.value = error _errorFlow.value = error
if (error.isNotEmpty()) stopTest = true
} }
disableStrategy(current.path, prefs) disableStrategy(current.path, prefs)
} }