feat: update app to check for updates on app open

This commit is contained in:
2026-05-13 22:22:53 +02:00
parent 7ec9a0f41f
commit 8950a37341
5 changed files with 32 additions and 11 deletions

View File

@@ -7,7 +7,6 @@ import hu.bbara.purefin.core.data.HomeRepository
import hu.bbara.purefin.core.data.LocalMediaRepository
import hu.bbara.purefin.core.data.UserSessionRepository
import hu.bbara.purefin.core.download.MediaDownloadController
import hu.bbara.purefin.core.feature.update.AppUpdateController
import hu.bbara.purefin.core.jellyfin.JellyfinMediaMetadataUpdater
import hu.bbara.purefin.core.model.EpisodeUiModel
import hu.bbara.purefin.core.model.LibraryUiModel
@@ -41,7 +40,6 @@ class AppViewModel @Inject constructor(
private val jellyfinMediaMetadataUpdater: JellyfinMediaMetadataUpdater,
private val navigationManager: NavigationManager,
private val mediaDownloadManager: MediaDownloadController,
private val appUpdateController: AppUpdateController,
) : ViewModel() {
private val _isRefreshing = MutableStateFlow(false)
@@ -241,10 +239,6 @@ class AppViewModel @Inject constructor(
viewModelScope.launch {
try {
homeRepository.refreshHomeData()
appUpdateController.checkForUpdates(
showUpToDateMessage = false,
showFailureMessage = false
)
} catch (e: Exception) {
// Refresh is best-effort; don't crash on failure
}
@@ -261,10 +255,6 @@ class AppViewModel @Inject constructor(
_isRefreshing.value = true
try {
homeRepository.refreshHomeData()
appUpdateController.checkForUpdates(
showUpToDateMessage = false,
showFailureMessage = false
)
} catch (e: Exception) {
// Refresh is best-effort; don't crash on failure
} finally {

View File

@@ -34,11 +34,13 @@ class AppUpdateController @Inject constructor(
private val checkMutex = Mutex()
private val installMutex = Mutex()
private var checkedForUpdatesOnAppOpen = false
override val settingGroups: Flow<List<SettingGroup>> = availableUpdate
.map { update ->
val options = listOfNotNull<SettingOption<*>>(
buildNumberSetting(),
checkForUpdatesSetting(),
update?.let { installUpdateSetting(it) }
)
@@ -75,6 +77,18 @@ class AppUpdateController @Inject constructor(
}
}
suspend fun checkForUpdatesOnAppOpen() {
if (checkedForUpdatesOnAppOpen) {
return
}
checkedForUpdatesOnAppOpen = true
checkForUpdates(
showUpToDateMessage = false,
showFailureMessage = false
)
}
suspend fun installAvailableUpdate() {
val update = _availableUpdate.value ?: return
if (!installMutex.tryLock()) {
@@ -110,8 +124,15 @@ class AppUpdateController @Inject constructor(
value = appVersionProvider.versionCode.toString()
)
private fun checkForUpdatesSetting() = VoidSetting(
key = CHECK_FOR_UPDATES_KEY,
title = "Check for updates",
onClick = { checkForUpdates() }
)
private companion object {
const val BUILD_NUMBER_KEY = "build_number"
const val CHECK_FOR_UPDATES_KEY = "check_for_updates"
const val INSTALL_APP_UPDATE_KEY = "install_app_update"
}
}

View File

@@ -25,6 +25,12 @@ class AppUpdateViewModel @Inject constructor(
}
}
fun checkForUpdatesOnAppOpen() {
viewModelScope.launch {
appUpdateController.checkForUpdatesOnAppOpen()
}
}
fun acceptUpdate() {
viewModelScope.launch {
appUpdateController.installAvailableUpdate()