You've already forked KernelSU-Next
mirror of
https://github.com/KernelSU-Next/KernelSU-Next.git
synced 2025-08-27 23:46:34 +00:00
manager: fix module list empty until refreshed manually
This commit is contained in:
@@ -10,8 +10,13 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.dergoogler.mmrl.platform.model.ModuleConfig
|
import com.dergoogler.mmrl.platform.model.ModuleConfig
|
||||||
import com.dergoogler.mmrl.platform.model.ModuleConfig.Companion.asModuleConfig
|
import com.dergoogler.mmrl.platform.model.ModuleConfig.Companion.asModuleConfig
|
||||||
|
import com.dergoogler.mmrl.platform.Platform
|
||||||
|
import com.dergoogler.mmrl.platform.TIMEOUT_MILLIS
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
import java.text.Collator
|
import java.text.Collator
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import com.rifsxd.ksunext.ksuApp
|
import com.rifsxd.ksunext.ksuApp
|
||||||
@@ -88,18 +93,30 @@ class ModuleViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun fetchModuleList() {
|
fun fetchModuleList() {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
isRefreshing = true
|
|
||||||
|
|
||||||
val oldModuleList = modules
|
viewModelScope.launch {
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
isRefreshing = true
|
||||||
|
}
|
||||||
|
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
withTimeoutOrNull(TIMEOUT_MILLIS) {
|
||||||
|
while (!Platform.isAlive) {
|
||||||
|
delay(500)
|
||||||
|
}
|
||||||
|
} ?: run {
|
||||||
|
isRefreshing = false
|
||||||
|
Log.e(TAG, "Platform is not alive, aborting fetchModuleList")
|
||||||
|
return@withContext
|
||||||
|
}
|
||||||
|
|
||||||
val start = SystemClock.elapsedRealtime()
|
val start = SystemClock.elapsedRealtime()
|
||||||
|
val oldModuleList = modules
|
||||||
|
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
isOverlayAvailable = overlayFsAvailable()
|
isOverlayAvailable = overlayFsAvailable()
|
||||||
|
|
||||||
val result = listModules()
|
val result = listModules()
|
||||||
|
|
||||||
Log.i(TAG, "result: $result")
|
Log.i(TAG, "result: $result")
|
||||||
|
|
||||||
val array = JSONArray(result)
|
val array = JSONArray(result)
|
||||||
@@ -142,6 +159,7 @@ class ModuleViewModel : ViewModel() {
|
|||||||
Log.i(TAG, "load cost: ${SystemClock.elapsedRealtime() - start}, modules: $modules")
|
Log.i(TAG, "load cost: ${SystemClock.elapsedRealtime() - start}, modules: $modules")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun sanitizeVersionString(version: String): String {
|
private fun sanitizeVersionString(version: String): String {
|
||||||
return version.replace(Regex("[^a-zA-Z0-9.\\-_]"), "_")
|
return version.replace(Regex("[^a-zA-Z0-9.\\-_]"), "_")
|
||||||
|
|||||||
Reference in New Issue
Block a user