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: do not go at the start of the superuser list and stay where you were after app profile changes (resolves #491)
This commit is contained in:
@@ -54,12 +54,6 @@ fun SuperUserScreen(navigator: DestinationsNavigator) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(viewModel.search) {
|
|
||||||
if (viewModel.search.isEmpty()) {
|
|
||||||
listState.scrollToItem(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
SearchAppBar(
|
SearchAppBar(
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class SuperUserViewModel : ViewModel() {
|
|||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "SuperUserViewModel"
|
private const val TAG = "SuperUserViewModel"
|
||||||
private var apps by mutableStateOf<List<AppInfo>>(emptyList())
|
private var apps by mutableStateOf<List<AppInfo>>(emptyList())
|
||||||
|
private var profileOverrides by mutableStateOf<Map<String, Natives.Profile>>(emptyMap())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
@@ -68,8 +69,10 @@ class SuperUserViewModel : ViewModel() {
|
|||||||
private val sortedList by derivedStateOf {
|
private val sortedList by derivedStateOf {
|
||||||
val comparator = compareBy<AppInfo> {
|
val comparator = compareBy<AppInfo> {
|
||||||
when {
|
when {
|
||||||
it.allowSu -> 0
|
it.profile != null && it.profile.allowSu -> 0
|
||||||
it.hasCustomProfile -> 1
|
it.profile != null && (
|
||||||
|
if (it.profile.allowSu) !it.profile.rootUseDefault else !it.profile.nonRootUseDefault
|
||||||
|
) -> 1
|
||||||
else -> 2
|
else -> 2
|
||||||
}
|
}
|
||||||
}.then(compareBy(Collator.getInstance(Locale.getDefault()), AppInfo::label))
|
}.then(compareBy(Collator.getInstance(Locale.getDefault()), AppInfo::label))
|
||||||
@@ -79,7 +82,9 @@ class SuperUserViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val appList by derivedStateOf {
|
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(
|
it.label.contains(search, true) || it.packageName.contains(
|
||||||
search,
|
search,
|
||||||
true
|
true
|
||||||
@@ -92,15 +97,14 @@ class SuperUserViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateAppProfile(packageName: String, newProfile: Natives.Profile) {
|
fun updateAppProfile(packageName: String, newProfile: Natives.Profile) {
|
||||||
apps = apps.map {
|
profileOverrides = profileOverrides.toMutableMap().apply {
|
||||||
if (it.packageName == packageName) it.copy(profile = newProfile) else it
|
put(packageName, newProfile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun fetchAppList() {
|
suspend fun fetchAppList() {
|
||||||
isRefreshing = true
|
isRefreshing = true
|
||||||
|
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
withTimeoutOrNull(TIMEOUT_MILLIS) {
|
withTimeoutOrNull(TIMEOUT_MILLIS) {
|
||||||
while (!isPlatformAlive) {
|
while (!isPlatformAlive) {
|
||||||
@@ -126,6 +130,7 @@ class SuperUserViewModel : ViewModel() {
|
|||||||
profile = profile,
|
profile = profile,
|
||||||
)
|
)
|
||||||
}.filter { it.packageName != ksuApp.packageName }
|
}.filter { it.packageName != ksuApp.packageName }
|
||||||
|
profileOverrides = emptyMap()
|
||||||
Log.i(TAG, "load cost: ${SystemClock.elapsedRealtime() - start}")
|
Log.i(TAG, "load cost: ${SystemClock.elapsedRealtime() - start}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user