fix ipsets loading

This commit is contained in:
CherretGit
2025-10-16 19:45:57 +07:00
parent 2954cef0a6
commit ad5c556241
3 changed files with 6 additions and 16 deletions

View File

@@ -9,6 +9,7 @@ import com.cherret.zaprett.utils.enableIpset
import com.cherret.zaprett.utils.enableList
import com.cherret.zaprett.utils.getActiveExcludeIpsets
import com.cherret.zaprett.utils.getActiveExcludeLists
import com.cherret.zaprett.utils.getActiveIpsets
import com.cherret.zaprett.utils.getAllExcludeIpsets
import com.cherret.zaprett.utils.getAllIpsets
import com.cherret.zaprett.utils.getHostListMode
@@ -23,8 +24,8 @@ class IpsetViewModel(application: Application): BaseListsViewModel(application)
if (getHostListMode(sharedPreferences) == "whitelist") getAllIpsets()
else getAllExcludeIpsets()
override fun loadActiveItems(): Array<String> =
if (getHostListMode(sharedPreferences) == "whitelist") getActiveExcludeIpsets(sharedPreferences)
else getActiveExcludeLists(sharedPreferences)
if (getHostListMode(sharedPreferences) == "whitelist") getActiveIpsets(sharedPreferences)
else getActiveExcludeIpsets(sharedPreferences)
override fun deleteItem(item: String, snackbarHostState: SnackbarHostState, scope: CoroutineScope) {
val wasChecked = checked[item] == true
@@ -61,5 +62,4 @@ class IpsetViewModel(application: Application): BaseListsViewModel(application)
setHostListMode(sharedPreferences, type)
refresh()
}
}

View File

@@ -38,10 +38,8 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
.callTimeout(prefs.getLong("probe_timeout", 1000L), TimeUnit.MILLISECONDS)
.build()
val context = application
private val _requestVpnPermission = MutableStateFlow(false)
val requestVpnPermission = _requestVpnPermission.asStateFlow()
val strategyStates = mutableStateListOf<StrategyCheckResult>()
init {
@@ -64,7 +62,6 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
val request = Request.Builder()
.url("https://${domain}")
.build()
try {
client.newCall(request).execute().use { response ->
response.isSuccessful || (response.code in 300..399)
@@ -100,19 +97,15 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
}
suspend fun performTest() {
val targets = readActiveListsLines()
for (index in strategyStates.indices) {
val current = strategyStates[index]
strategyStates[index] = current.copy(status = R.string.strategy_status_testing)
enableStrategy(current.path, prefs)
if (prefs.getBoolean("use_module", false)) {
getStatus { if (it) stopService {} }
startService {}
try {
val progress = countReachable(targets)
val old = strategyStates[index]
strategyStates[index] = old.copy(
progress = progress,
@@ -134,14 +127,12 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
/*context.startService(Intent(context, ByeDpiVpnService::class.java).apply {
action = "START_VPN"
})*/
val connected = withTimeoutOrNull(10_000L) {
while (ByeDpiVpnService.status != ServiceStatus.Connected) {
delay(100L)
}
true
} ?: false
if (connected) delay(150L)
try {
val progress = countReachable(targets)
@@ -160,7 +151,6 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
}
}
}
val sorted = strategyStates.sortedByDescending { it.progress }
strategyStates.clear()
strategyStates.addAll(sorted)

View File

@@ -192,7 +192,7 @@ fun getActiveIpsets(sharedPreferences: SharedPreferences): Array<String> {
}
return emptyArray()
}
else return emptyArray()
else return sharedPreferences.getStringSet("ipsets", emptySet())?.toTypedArray() ?: emptyArray()
}
fun getActiveExcludeLists(sharedPreferences: SharedPreferences): Array<String> {
if (sharedPreferences.getBoolean("use_module", false)) {
@@ -236,7 +236,7 @@ fun getActiveExcludeIpsets(sharedPreferences: SharedPreferences): Array<String>
}
return emptyArray()
}
else return emptyArray()
else return sharedPreferences.getStringSet("exclude_ipsets", emptySet())?.toTypedArray() ?: emptyArray()
}
fun getActiveNfqwsStrategy(): Array<String> {
@@ -363,7 +363,7 @@ fun enableIpset(path: String, sharedPreferences: SharedPreferences) {
currentSet.add(path)
sharedPreferences.edit { putStringSet(
if (getHostListMode(sharedPreferences) == "whitelist") "ipsets"
else "exclude_ipsetss", currentSet) }
else "exclude_ipsets", currentSet) }
}
}
}