From 9267636f62b568f039bd0786a0d996a2fddb0965 Mon Sep 17 00:00:00 2001 From: tapframe <85391825+tapframe@users.noreply.github.com> Date: Sun, 19 Apr 2026 02:02:44 +0530 Subject: [PATCH] fix: update state management for app updater --- .../nuvio/app/features/updater/AppUpdater.kt | 57 +++++++++++-------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/updater/AppUpdater.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/updater/AppUpdater.kt index 7711facb..302e860e 100644 --- a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/updater/AppUpdater.kt +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/updater/AppUpdater.kt @@ -257,8 +257,11 @@ class AppUpdaterController internal constructor( _uiState.update { state -> state.copy( isChecking = false, - update = update, + update = update.takeIf { remoteNewer }, isUpdateAvailable = remoteNewer, + isDownloading = false, + downloadProgress = null, + downloadedApkPath = state.downloadedApkPath.takeIf { remoteNewer }, showDialog = shouldShowDialog, showUnknownSourcesDialog = false, errorMessage = null, @@ -272,6 +275,9 @@ class AppUpdaterController internal constructor( _uiState.update { state -> state.copy( isChecking = false, + isDownloading = false, + downloadProgress = null, + downloadedApkPath = null, update = null, isUpdateAvailable = false, showDialog = force && error !is NoChannelReleaseException, @@ -405,6 +411,9 @@ fun AppUpdaterHost( if (!state.showDialog) return + val showPrimaryAction = + state.showUnknownSourcesDialog || state.isDownloading || state.downloadedApkPath != null || state.isUpdateAvailable + BasicAlertDialog( onDismissRequest = { if (!state.isDownloading) { @@ -540,29 +549,31 @@ fun AppUpdaterHost( modifier = Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(10.dp), ) { - Button( - modifier = Modifier.fillMaxWidth(), - onClick = { - when { - state.showUnknownSourcesDialog -> controller.resumeInstallation() - 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" + if (showPrimaryAction) { + Button( + modifier = Modifier.fillMaxWidth(), + onClick = { + when { + state.showUnknownSourcesDialog -> controller.resumeInstallation() + state.downloadedApkPath != null -> controller.installDownloadedUpdate() + else -> controller.downloadUpdate() + } }, - ) + 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) {