fix incorrect state when actions are not taken at launch

This commit is contained in:
Chloe committed 2025-12-19 04:18:10 -07:00
1 parent 53a67f3e43
commit 3887c3fe60
1 file changed
+15 -2
@@ -82,7 +82,20 @@ class LaunchViewModel(private val application: Application): ViewModel() {
data object Ready : LaunchUIState()
}
private val _uiState = MutableStateFlow<LaunchUIState>(LaunchUIState.Initial)
private val _uiState: MutableStateFlow<LaunchUIState>
init {
val preferenceUtils = PreferenceUtils.get(application)
val initialCancel = !preferenceUtils.getBoolean(PreferenceUtils.Key.UPDATE_AUTOMATICALLY)
&& !preferenceUtils.getBoolean(PreferenceUtils.Key.LOAD_AUTOMATICALLY)
// fixes a single frame of progress being displayed when we're not actually going to do work
_uiState = MutableStateFlow<LaunchUIState>(
if (initialCancel) LaunchUIState.Cancelled(LaunchCancelReason.AUTOMATIC)
else LaunchUIState.Initial
)
}
val uiState = _uiState.asStateFlow()
val nextLauncherUpdate = ReleaseManager.get(application).availableLauncherUpdate
@@ -210,10 +223,10 @@ class LaunchViewModel(private val application: Application): ViewModel() {
val reason = if (isAutomatic) LaunchCancelReason.AUTOMATIC else LaunchCancelReason.MANUAL
isCancelling = true
_uiState.emit(LaunchUIState.Cancelled(reason, true))
val releaseManager = ReleaseManager.get(application)
if (releaseManager.isInUpdate) {
_uiState.emit(LaunchUIState.Cancelled(reason, true))
releaseManager.cancelUpdate()
}