diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/service/CoreTestService.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/service/CoreTestService.kt index 73a93be84..ffb9b919a 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/service/CoreTestService.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/service/CoreTestService.kt @@ -10,6 +10,7 @@ import com.v2ray.ang.dto.RealPingEvent import com.v2ray.ang.dto.TestServiceMessage import com.v2ray.ang.enums.NotificationChannelType import com.v2ray.ang.extension.serializable +import com.v2ray.ang.handler.AngConfigManager import com.v2ray.ang.handler.MmkvManager import com.v2ray.ang.helper.MessageHelper import com.v2ray.ang.helper.NotificationHelper @@ -96,7 +97,7 @@ class CoreTestService : Service() { context = this, guids = guidsList, onlyTcp = message.onlyTcp, - onEvent = { event -> handleWorkerEvent(event) { activeWorkers.remove(worker) } } + onEvent = { event -> handleWorkerEvent(event, message) { activeWorkers.remove(worker) } } ) activeWorkers.add(worker) worker.start() @@ -106,7 +107,7 @@ class CoreTestService : Service() { } } - private fun handleWorkerEvent(event: RealPingEvent, onWorkerDone: () -> Unit) { + private fun handleWorkerEvent(event: RealPingEvent, message: TestServiceMessage, onWorkerDone: () -> Unit) { when (event) { is RealPingEvent.Progress -> { NotificationHelper.updateNotification( @@ -124,6 +125,16 @@ class CoreTestService : Service() { } is RealPingEvent.Finish -> { + if(message.subscriptionId.isNotEmpty()){ + if (MmkvManager.decodeSettingsBool(AppConfig.PREF_AUTO_REMOVE_INVALID_AFTER_TEST, false)) { + AngConfigManager.removeInvalidServer(message.subscriptionId) + } + + if (MmkvManager.decodeSettingsBool(AppConfig.PREF_AUTO_SORT_AFTER_TEST, false)) { + AngConfigManager.sortByTestResultsForSub(message.subscriptionId) + } + } + MessageHelper.sendMsg2UI(this, AppConfig.MSG_MEASURE_CONFIG_FINISH, event.status) onWorkerDone() if (activeWorkers.isEmpty()) {