mirror of
https://github.com/CherretGit/zaprett-app.git
synced 2025-12-10 05:29:37 +05:00
fix ipsets loading
This commit is contained in:
@@ -9,6 +9,7 @@ import com.cherret.zaprett.utils.enableIpset
|
|||||||
import com.cherret.zaprett.utils.enableList
|
import com.cherret.zaprett.utils.enableList
|
||||||
import com.cherret.zaprett.utils.getActiveExcludeIpsets
|
import com.cherret.zaprett.utils.getActiveExcludeIpsets
|
||||||
import com.cherret.zaprett.utils.getActiveExcludeLists
|
import com.cherret.zaprett.utils.getActiveExcludeLists
|
||||||
|
import com.cherret.zaprett.utils.getActiveIpsets
|
||||||
import com.cherret.zaprett.utils.getAllExcludeIpsets
|
import com.cherret.zaprett.utils.getAllExcludeIpsets
|
||||||
import com.cherret.zaprett.utils.getAllIpsets
|
import com.cherret.zaprett.utils.getAllIpsets
|
||||||
import com.cherret.zaprett.utils.getHostListMode
|
import com.cherret.zaprett.utils.getHostListMode
|
||||||
@@ -23,8 +24,8 @@ class IpsetViewModel(application: Application): BaseListsViewModel(application)
|
|||||||
if (getHostListMode(sharedPreferences) == "whitelist") getAllIpsets()
|
if (getHostListMode(sharedPreferences) == "whitelist") getAllIpsets()
|
||||||
else getAllExcludeIpsets()
|
else getAllExcludeIpsets()
|
||||||
override fun loadActiveItems(): Array<String> =
|
override fun loadActiveItems(): Array<String> =
|
||||||
if (getHostListMode(sharedPreferences) == "whitelist") getActiveExcludeIpsets(sharedPreferences)
|
if (getHostListMode(sharedPreferences) == "whitelist") getActiveIpsets(sharedPreferences)
|
||||||
else getActiveExcludeLists(sharedPreferences)
|
else getActiveExcludeIpsets(sharedPreferences)
|
||||||
|
|
||||||
override fun deleteItem(item: String, snackbarHostState: SnackbarHostState, scope: CoroutineScope) {
|
override fun deleteItem(item: String, snackbarHostState: SnackbarHostState, scope: CoroutineScope) {
|
||||||
val wasChecked = checked[item] == true
|
val wasChecked = checked[item] == true
|
||||||
@@ -61,5 +62,4 @@ class IpsetViewModel(application: Application): BaseListsViewModel(application)
|
|||||||
setHostListMode(sharedPreferences, type)
|
setHostListMode(sharedPreferences, type)
|
||||||
refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -38,10 +38,8 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
|
|||||||
.callTimeout(prefs.getLong("probe_timeout", 1000L), TimeUnit.MILLISECONDS)
|
.callTimeout(prefs.getLong("probe_timeout", 1000L), TimeUnit.MILLISECONDS)
|
||||||
.build()
|
.build()
|
||||||
val context = application
|
val context = application
|
||||||
|
|
||||||
private val _requestVpnPermission = MutableStateFlow(false)
|
private val _requestVpnPermission = MutableStateFlow(false)
|
||||||
val requestVpnPermission = _requestVpnPermission.asStateFlow()
|
val requestVpnPermission = _requestVpnPermission.asStateFlow()
|
||||||
|
|
||||||
val strategyStates = mutableStateListOf<StrategyCheckResult>()
|
val strategyStates = mutableStateListOf<StrategyCheckResult>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -64,7 +62,6 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
|
|||||||
val request = Request.Builder()
|
val request = Request.Builder()
|
||||||
.url("https://${domain}")
|
.url("https://${domain}")
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.newCall(request).execute().use { response ->
|
client.newCall(request).execute().use { response ->
|
||||||
response.isSuccessful || (response.code in 300..399)
|
response.isSuccessful || (response.code in 300..399)
|
||||||
@@ -100,19 +97,15 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
|
|||||||
}
|
}
|
||||||
suspend fun performTest() {
|
suspend fun performTest() {
|
||||||
val targets = readActiveListsLines()
|
val targets = readActiveListsLines()
|
||||||
|
|
||||||
for (index in strategyStates.indices) {
|
for (index in strategyStates.indices) {
|
||||||
val current = strategyStates[index]
|
val current = strategyStates[index]
|
||||||
strategyStates[index] = current.copy(status = R.string.strategy_status_testing)
|
strategyStates[index] = current.copy(status = R.string.strategy_status_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 {} }
|
getStatus { if (it) stopService {} }
|
||||||
startService {}
|
startService {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val progress = countReachable(targets)
|
val progress = countReachable(targets)
|
||||||
|
|
||||||
val old = strategyStates[index]
|
val old = strategyStates[index]
|
||||||
strategyStates[index] = old.copy(
|
strategyStates[index] = old.copy(
|
||||||
progress = progress,
|
progress = progress,
|
||||||
@@ -134,14 +127,12 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
|
|||||||
/*context.startService(Intent(context, ByeDpiVpnService::class.java).apply {
|
/*context.startService(Intent(context, ByeDpiVpnService::class.java).apply {
|
||||||
action = "START_VPN"
|
action = "START_VPN"
|
||||||
})*/
|
})*/
|
||||||
|
|
||||||
val connected = withTimeoutOrNull(10_000L) {
|
val connected = withTimeoutOrNull(10_000L) {
|
||||||
while (ByeDpiVpnService.status != ServiceStatus.Connected) {
|
while (ByeDpiVpnService.status != ServiceStatus.Connected) {
|
||||||
delay(100L)
|
delay(100L)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
} ?: false
|
} ?: false
|
||||||
|
|
||||||
if (connected) delay(150L)
|
if (connected) delay(150L)
|
||||||
try {
|
try {
|
||||||
val progress = countReachable(targets)
|
val progress = countReachable(targets)
|
||||||
@@ -160,7 +151,6 @@ class StrategySelectionViewModel(application: Application) : AndroidViewModel(ap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val sorted = strategyStates.sortedByDescending { it.progress }
|
val sorted = strategyStates.sortedByDescending { it.progress }
|
||||||
strategyStates.clear()
|
strategyStates.clear()
|
||||||
strategyStates.addAll(sorted)
|
strategyStates.addAll(sorted)
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ fun getActiveIpsets(sharedPreferences: SharedPreferences): Array<String> {
|
|||||||
}
|
}
|
||||||
return emptyArray()
|
return emptyArray()
|
||||||
}
|
}
|
||||||
else return emptyArray()
|
else return sharedPreferences.getStringSet("ipsets", emptySet())?.toTypedArray() ?: emptyArray()
|
||||||
}
|
}
|
||||||
fun getActiveExcludeLists(sharedPreferences: SharedPreferences): Array<String> {
|
fun getActiveExcludeLists(sharedPreferences: SharedPreferences): Array<String> {
|
||||||
if (sharedPreferences.getBoolean("use_module", false)) {
|
if (sharedPreferences.getBoolean("use_module", false)) {
|
||||||
@@ -236,7 +236,7 @@ fun getActiveExcludeIpsets(sharedPreferences: SharedPreferences): Array<String>
|
|||||||
}
|
}
|
||||||
return emptyArray()
|
return emptyArray()
|
||||||
}
|
}
|
||||||
else return emptyArray()
|
else return sharedPreferences.getStringSet("exclude_ipsets", emptySet())?.toTypedArray() ?: emptyArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getActiveNfqwsStrategy(): Array<String> {
|
fun getActiveNfqwsStrategy(): Array<String> {
|
||||||
@@ -363,7 +363,7 @@ fun enableIpset(path: String, sharedPreferences: SharedPreferences) {
|
|||||||
currentSet.add(path)
|
currentSet.add(path)
|
||||||
sharedPreferences.edit { putStringSet(
|
sharedPreferences.edit { putStringSet(
|
||||||
if (getHostListMode(sharedPreferences) == "whitelist") "ipsets"
|
if (getHostListMode(sharedPreferences) == "whitelist") "ipsets"
|
||||||
else "exclude_ipsetss", currentSet) }
|
else "exclude_ipsets", currentSet) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user