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,29 +549,31 @@ fun AppUpdaterHost(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp),
) { ) {
Button( if (showPrimaryAction) {
modifier = Modifier.fillMaxWidth(), Button(
onClick = { modifier = Modifier.fillMaxWidth(),
when { onClick = {
state.showUnknownSourcesDialog -> controller.resumeInstallation() when {
state.downloadedApkPath != null -> controller.installDownloadedUpdate() state.showUnknownSourcesDialog -> controller.resumeInstallation()
else -> controller.downloadUpdate() state.downloadedApkPath != null -> controller.installDownloadedUpdate()
} else -> controller.downloadUpdate()
}, }
enabled = if (state.showUnknownSourcesDialog || state.downloadedApkPath != null) {
true
} else {
!state.isChecking && !state.isDownloading && state.update != null
},
) {
Text(
when {
state.showUnknownSourcesDialog -> "Continue"
state.downloadedApkPath != null -> "Install"
state.isDownloading -> "Downloading"
else -> "Update"
}, },
) enabled = if (state.showUnknownSourcesDialog || state.downloadedApkPath != null) {
true
} else {
!state.isChecking && !state.isDownloading && state.isUpdateAvailable
},
) {
Text(
when {
state.showUnknownSourcesDialog -> "Continue"
state.downloadedApkPath != null -> "Install"
state.isDownloading -> "Downloading"
else -> "Update"
},
)
}
} }
if (state.isUpdateAvailable && !state.isDownloading && !state.showUnknownSourcesDialog) { if (state.isUpdateAvailable && !state.isDownloading && !state.showUnknownSourcesDialog) {