From 2fb70305275758e76cd21f23c099c99091806623 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Tue, 3 Mar 2026 22:25:36 +0800 Subject: [PATCH] Fix revoke dialog showing after navigating back from Superuser detail The revoke click handler called onBack() immediately after triggering the dialog event, causing the dialog to appear on the wrong screen. Defer navigation to the onDeleted callback so the dialog stays on the detail screen and back only happens after confirmation. Made-with: Cursor --- .../magisk/ui/superuser/SuperuserDetailScreen.kt | 3 +-- .../magisk/ui/superuser/SuperuserViewModel.kt | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserDetailScreen.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserDetailScreen.kt index fc37cc220..bfc06cbcc 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserDetailScreen.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserDetailScreen.kt @@ -152,8 +152,7 @@ fun SuperuserDetailScreen( modifier = Modifier .fillMaxWidth() .clickable { - viewModel.deletePressed(item) - onBack() + viewModel.deletePressed(item, onDeleted = onBack) } ) { RevokeRow() diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt index 8b4f60e5c..ebd551a40 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt @@ -20,8 +20,6 @@ import com.topjohnwu.magisk.core.ktx.getLabel import com.topjohnwu.magisk.core.model.su.SuPolicy import com.topjohnwu.magisk.dialog.SuperuserRevokeDialog import com.topjohnwu.magisk.events.AuthEvent -import com.topjohnwu.magisk.events.SnackbarEvent -import com.topjohnwu.magisk.utils.asText import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -115,12 +113,13 @@ class SuperuserViewModel( _uiState.update { it.copy(suRestrict = Config.suRestrict) } } - fun deletePressed(item: PolicyItem) { + fun deletePressed(item: PolicyItem, onDeleted: () -> Unit = {}) { fun updateState() = viewModelScope.launch { db.delete(item.policy.uid) _uiState.update { state -> state.copy(policies = state.policies.filter { it.policy.uid != item.policy.uid }) } + onDeleted() } if (Config.suAuth) { @@ -139,7 +138,7 @@ class SuperuserViewModel( .filter { it.policy.uid == item.policy.uid } .forEach { it.notification = item.notification } val res = if (item.notification) R.string.su_snack_notif_on else R.string.su_snack_notif_off - SnackbarEvent(res.asText(item.appName)).publish() + showSnackbar(AppContext.getString(res, item.appName)) } } @@ -152,7 +151,7 @@ class SuperuserViewModel( .filter { it.policy.uid == item.policy.uid } .forEach { it.logging = item.logging } val res = if (item.logging) R.string.su_snack_log_on else R.string.su_snack_log_off - SnackbarEvent(res.asText(item.appName)).publish() + showSnackbar(AppContext.getString(res, item.appName)) } } @@ -166,7 +165,7 @@ class SuperuserViewModel( .filter { it.policy.uid == item.policy.uid } .forEach { it.policyValue = newPolicy } val res = if (newPolicy >= SuPolicy.ALLOW) R.string.su_snack_grant else R.string.su_snack_deny - SnackbarEvent(res.asText(item.appName)).publish() + showSnackbar(AppContext.getString(res, item.appName)) } }