fix: update state management for app updater

This commit is contained in:
tapframe 2026-04-19 02:02:44 +05:30
parent 56997df8e2
commit 9267636f62

View file

@ -257,8 +257,11 @@ class AppUpdaterController internal constructor(
_uiState.update { state -> _uiState.update { state ->
state.copy( state.copy(
isChecking = false, isChecking = false,
update = update, update = update.takeIf { remoteNewer },
isUpdateAvailable = remoteNewer, isUpdateAvailable = remoteNewer,
isDownloading = false,
downloadProgress = null,
downloadedApkPath = state.downloadedApkPath.takeIf { remoteNewer },
showDialog = shouldShowDialog, showDialog = shouldShowDialog,
showUnknownSourcesDialog = false, showUnknownSourcesDialog = false,
errorMessage = null, errorMessage = null,
@ -272,6 +275,9 @@ class AppUpdaterController internal constructor(
_uiState.update { state -> _uiState.update { state ->
state.copy( state.copy(
isChecking = false, isChecking = false,
isDownloading = false,
downloadProgress = null,
downloadedApkPath = null,
update = null, update = null,
isUpdateAvailable = false, isUpdateAvailable = false,
showDialog = force && error !is NoChannelReleaseException, showDialog = force && error !is NoChannelReleaseException,
@ -405,6 +411,9 @@ fun AppUpdaterHost(
if (!state.showDialog) return if (!state.showDialog) return
val showPrimaryAction =
state.showUnknownSourcesDialog || state.isDownloading || state.downloadedApkPath != null || state.isUpdateAvailable
BasicAlertDialog( BasicAlertDialog(
onDismissRequest = { onDismissRequest = {
if (!state.isDownloading) { if (!state.isDownloading) {
@ -540,6 +549,7 @@ fun AppUpdaterHost(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp),
) { ) {
if (showPrimaryAction) {
Button( Button(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
onClick = { onClick = {
@ -552,7 +562,7 @@ fun AppUpdaterHost(
enabled = if (state.showUnknownSourcesDialog || state.downloadedApkPath != null) { enabled = if (state.showUnknownSourcesDialog || state.downloadedApkPath != null) {
true true
} else { } else {
!state.isChecking && !state.isDownloading && state.update != null !state.isChecking && !state.isDownloading && state.isUpdateAvailable
}, },
) { ) {
Text( Text(
@ -564,6 +574,7 @@ fun AppUpdaterHost(
}, },
) )
} }
}
if (state.isUpdateAvailable && !state.isDownloading && !state.showUnknownSourcesDialog) { if (state.isUpdateAvailable && !state.isDownloading && !state.showUnknownSourcesDialog) {
Row( Row(