From 057388ccef3b26393c1691249cfcfc000541543a Mon Sep 17 00:00:00 2001 From: Rifat Azad Date: Thu, 12 Jun 2025 10:42:53 +0600 Subject: [PATCH] manager: do not go at the start of the superuser list and stay where you were after app profile changes (resolves #491) --- .../com/rifsxd/ksunext/ui/screen/SuperUser.kt | 6 ------ .../ksunext/ui/viewmodel/SuperUserViewModel.kt | 17 +++++++++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/SuperUser.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/SuperUser.kt index fcab5d91..f3ed31f3 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/SuperUser.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/SuperUser.kt @@ -54,12 +54,6 @@ fun SuperUserScreen(navigator: DestinationsNavigator) { } } - LaunchedEffect(viewModel.search) { - if (viewModel.search.isEmpty()) { - listState.scrollToItem(0) - } - } - Scaffold( topBar = { SearchAppBar( diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/viewmodel/SuperUserViewModel.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/viewmodel/SuperUserViewModel.kt index dc48580b..58743785 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/viewmodel/SuperUserViewModel.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/viewmodel/SuperUserViewModel.kt @@ -31,6 +31,7 @@ class SuperUserViewModel : ViewModel() { companion object { private const val TAG = "SuperUserViewModel" private var apps by mutableStateOf>(emptyList()) + private var profileOverrides by mutableStateOf>(emptyMap()) } @Parcelize @@ -68,8 +69,10 @@ class SuperUserViewModel : ViewModel() { private val sortedList by derivedStateOf { val comparator = compareBy { when { - it.allowSu -> 0 - it.hasCustomProfile -> 1 + it.profile != null && it.profile.allowSu -> 0 + it.profile != null && ( + if (it.profile.allowSu) !it.profile.rootUseDefault else !it.profile.nonRootUseDefault + ) -> 1 else -> 2 } }.then(compareBy(Collator.getInstance(Locale.getDefault()), AppInfo::label)) @@ -79,7 +82,9 @@ class SuperUserViewModel : ViewModel() { } val appList by derivedStateOf { - sortedList.filter { + sortedList.map { app -> + profileOverrides[app.packageName]?.let { app.copy(profile = it) } ?: app + }.filter { it.label.contains(search, true) || it.packageName.contains( search, true @@ -92,15 +97,14 @@ class SuperUserViewModel : ViewModel() { } fun updateAppProfile(packageName: String, newProfile: Natives.Profile) { - apps = apps.map { - if (it.packageName == packageName) it.copy(profile = newProfile) else it + profileOverrides = profileOverrides.toMutableMap().apply { + put(packageName, newProfile) } } suspend fun fetchAppList() { isRefreshing = true - withContext(Dispatchers.IO) { withTimeoutOrNull(TIMEOUT_MILLIS) { while (!isPlatformAlive) { @@ -126,6 +130,7 @@ class SuperUserViewModel : ViewModel() { profile = profile, ) }.filter { it.packageName != ksuApp.packageName } + profileOverrides = emptyMap() Log.i(TAG, "load cost: ${SystemClock.elapsedRealtime() - start}") } }