mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
app: keep Home dialog state across recreation
Two Home dialogs didn't restore their data with their visibility: - The "abnormal state" dialog kept its visibility in saved state but its exit code in plain remember. After a rotation the code was 0, so for code 2, which needs a full reinstall, it offered the quick fix (fix environment and reboot) instead. - The app install dialog read the update from Info.update, which is reset on every connectivity change, including each time the app comes to the foreground, and after process death. It then showed empty notes and downloaded an empty link. Save the exit code, and keep the update shown by the Home screen in the ViewModel and in the dialog's saved state, passing it to the download. Assisted-by: Claude Opus 5.5
This commit is contained in:
@@ -79,6 +79,7 @@ import com.topjohnwu.magisk.core.Info
|
||||
import com.topjohnwu.magisk.core.download.DownloadEngine
|
||||
import com.topjohnwu.magisk.core.download.Subject
|
||||
import com.topjohnwu.magisk.core.ktx.reboot
|
||||
import com.topjohnwu.magisk.core.model.UpdateInfo
|
||||
import com.topjohnwu.magisk.ui.MainActivity
|
||||
import com.topjohnwu.magisk.ui.component.AdaptiveColumns
|
||||
import com.topjohnwu.magisk.ui.component.LoadingDialog
|
||||
@@ -106,10 +107,12 @@ fun HomeScreen(
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
|
||||
var showUninstallDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showManagerDialog by rememberSaveable { mutableStateOf(false) }
|
||||
// Keep the update itself, so a restored dialog doesn't depend on Info.update, which is reset
|
||||
// on connectivity changes and after process death
|
||||
var managerUpdate by rememberSaveable { mutableStateOf<UpdateInfo?>(null) }
|
||||
var showEnvFixDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showInstallDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var envFixCode by remember { mutableIntStateOf(0) }
|
||||
var envFixCode by rememberSaveable { mutableIntStateOf(0) }
|
||||
|
||||
LaunchedEffect(uiState.showUninstall) {
|
||||
if (uiState.showUninstall) {
|
||||
@@ -118,8 +121,8 @@ fun HomeScreen(
|
||||
}
|
||||
}
|
||||
LaunchedEffect(uiState.showManagerInstall) {
|
||||
if (uiState.showManagerInstall) {
|
||||
showManagerDialog = true
|
||||
uiState.showManagerInstall?.let {
|
||||
managerUpdate = it
|
||||
viewModel.onManagerInstallConsumed()
|
||||
}
|
||||
}
|
||||
@@ -148,14 +151,15 @@ fun HomeScreen(
|
||||
)
|
||||
}
|
||||
|
||||
if (showManagerDialog) {
|
||||
managerUpdate?.let { update ->
|
||||
ManagerInstallComposableDialog(
|
||||
update = update,
|
||||
cacheDir = context.cacheDir,
|
||||
onDismiss = { showManagerDialog = false },
|
||||
onDismiss = { managerUpdate = null },
|
||||
onInstall = {
|
||||
showManagerDialog = false
|
||||
managerUpdate = null
|
||||
(context as? MainActivity)?.let {
|
||||
DownloadEngine.startWithActivity(it, Subject.App())
|
||||
DownloadEngine.startWithActivity(it, Subject.App(update))
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -818,6 +822,7 @@ private fun UninstallComposableDialog(
|
||||
|
||||
@Composable
|
||||
private fun ManagerInstallComposableDialog(
|
||||
update: UpdateInfo,
|
||||
cacheDir: File,
|
||||
onDismiss: () -> Unit,
|
||||
onInstall: () -> Unit,
|
||||
@@ -834,8 +839,8 @@ private fun ManagerInstallComposableDialog(
|
||||
scrollable = true,
|
||||
) {
|
||||
MarkdownTextAsync {
|
||||
val text = Info.update.note
|
||||
File(cacheDir, "${Info.update.versionCode}.md").writeText(text)
|
||||
val text = update.note
|
||||
File(cacheDir, "${update.versionCode}.md").writeText(text)
|
||||
text
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.topjohnwu.magisk.core.Info
|
||||
import com.topjohnwu.magisk.core.ktx.await
|
||||
import com.topjohnwu.magisk.core.ktx.reboot
|
||||
import com.topjohnwu.magisk.core.ktx.toast
|
||||
import com.topjohnwu.magisk.core.model.UpdateInfo
|
||||
import com.topjohnwu.magisk.core.repository.NetworkService
|
||||
import com.topjohnwu.magisk.core.tasks.MagiskInstaller
|
||||
import com.topjohnwu.magisk.utils.asFlow
|
||||
@@ -41,7 +42,8 @@ class HomeViewModel(
|
||||
val managerRemoteVersion: String = "",
|
||||
val managerProgress: Int = 0,
|
||||
val showUninstall: Boolean = false,
|
||||
val showManagerInstall: Boolean = false,
|
||||
// The update to show in the app install dialog, as one-shot event
|
||||
val showManagerInstall: UpdateInfo? = null,
|
||||
val envFixCode: Int = 0,
|
||||
val showLoading: Boolean = false,
|
||||
val magiskState: State = computeMagiskState(),
|
||||
@@ -49,6 +51,9 @@ class HomeViewModel(
|
||||
val managerInstalledVersion: String = computeManagerInstalledVersion(),
|
||||
)
|
||||
|
||||
// Info.update is reset on every connectivity change, so keep the update that the UI shows
|
||||
private var latestUpdate: UpdateInfo? = null
|
||||
|
||||
private val _uiState = MutableStateFlow(UiState())
|
||||
val uiState: StateFlow<UiState> = _uiState.asStateFlow()
|
||||
|
||||
@@ -96,6 +101,7 @@ class HomeViewModel(
|
||||
)
|
||||
}
|
||||
Info.fetchUpdate(svc)?.apply {
|
||||
latestUpdate = this
|
||||
val isDebug = Config.updateChannel == Config.Value.DEBUG_CHANNEL
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
@@ -131,12 +137,13 @@ class HomeViewModel(
|
||||
when (_uiState.value.appState) {
|
||||
State.LOADING -> showToast(CoreR.string.loading)
|
||||
State.INVALID -> showToast(CoreR.string.no_connection)
|
||||
else -> _uiState.update { it.copy(showManagerInstall = true) }
|
||||
else -> latestUpdate?.let { info -> _uiState.update { it.copy(showManagerInstall = info) } }
|
||||
?: showToast(CoreR.string.no_connection)
|
||||
}
|
||||
}
|
||||
|
||||
fun onManagerInstallConsumed() {
|
||||
_uiState.update { it.copy(showManagerInstall = false) }
|
||||
_uiState.update { it.copy(showManagerInstall = null) }
|
||||
}
|
||||
|
||||
fun onEnvFixConsumed() {
|
||||
|
||||
Reference in New Issue
Block a user