mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
app: keep lists while refreshing
The superuser, log and module lists are refreshed whenever their tab is shown, when returning to the main screen, after configuration changes, and on other events (the module list on every activity start, the logs on every superuser request). Each refresh set the loading flag, which replaced the list with a spinner, so the list lost its scroll position and expanded cards collapsed. Module update buttons also disappeared until update info was fetched again. The DenyList even scanned every installed app again on rotation. Only show the loading state until the first load finishes, keep update info of unchanged modules across refreshes, and scan apps for the DenyList only once per screen. Assisted-by: Claude Opus 5.5
This commit is contained in:
@@ -181,6 +181,9 @@ class DenyListViewModel : AsyncLoadViewModel() {
|
||||
}
|
||||
|
||||
override suspend fun doLoadWork() {
|
||||
// Scanning every app is slow and resets the list, so only do it once: this is called
|
||||
// again whenever the screen is recreated, e.g. on rotation
|
||||
if (_allApps.value.isNotEmpty()) return
|
||||
_loading.value = true
|
||||
val apps = withContext(Dispatchers.Default) {
|
||||
val pm = AppContext.packageManager
|
||||
|
||||
@@ -47,7 +47,8 @@ class LogViewModel(
|
||||
private var magiskLogRaw = ""
|
||||
|
||||
override suspend fun doLoadWork() {
|
||||
_uiState.update { it.copy(loading = true) }
|
||||
// Keep showing the current list while refreshing: loading is only true until the first
|
||||
// load finishes, so a refresh doesn't swap the list for a spinner and lose its scroll
|
||||
withContext(Dispatchers.Default) {
|
||||
magiskLogRaw = repo.fetchMagiskLogs()
|
||||
val suLogs = if (Info.env.isActive) repo.fetchSuLogs() else emptyList()
|
||||
|
||||
@@ -83,12 +83,24 @@ class ModuleViewModel : AsyncLoadViewModel() {
|
||||
}
|
||||
|
||||
override suspend fun doLoadWork() {
|
||||
_uiState.update { it.copy(loading = true) }
|
||||
// Keep showing the current list while refreshing: loading is only true until the first
|
||||
// load finishes, so a refresh doesn't swap the list for a spinner and lose its scroll
|
||||
val moduleLoaded = Info.env.isActive &&
|
||||
withContext(Dispatchers.IO) { LocalModule.loaded() }
|
||||
if (moduleLoaded) {
|
||||
val previous = _uiState.value.modules.associateBy { it.module.base.name }
|
||||
val modules = withContext(Dispatchers.Default) {
|
||||
LocalModule.installed().map { ModuleItem(it) }
|
||||
LocalModule.installed().map { module ->
|
||||
// Keep the update info of the same module version until it is fetched
|
||||
// again, so update buttons don't disappear on every refresh
|
||||
previous[module.base.name]?.module
|
||||
?.takeIf { it.versionCode == module.versionCode }
|
||||
?.let {
|
||||
module.updateInfo = it.updateInfo
|
||||
module.outdated = it.outdated
|
||||
}
|
||||
ModuleItem(module)
|
||||
}
|
||||
}
|
||||
_uiState.update { it.copy(loading = false, modules = modules) }
|
||||
loadUpdateInfo()
|
||||
|
||||
@@ -75,7 +75,8 @@ class SuperuserViewModel(
|
||||
_uiState.update { it.copy(loading = false) }
|
||||
return
|
||||
}
|
||||
_uiState.update { it.copy(loading = true) }
|
||||
// Keep showing the current list while refreshing: loading is only true until the first
|
||||
// load finishes, so a refresh doesn't swap the list for a spinner and lose its scroll
|
||||
writeLock.withLock {
|
||||
val loaded = withContext(Dispatchers.IO) {
|
||||
db.deleteOutdated()
|
||||
|
||||
Reference in New Issue
Block a user