mirror of
https://github.com/bbara04/Purefin.git
synced 2026-07-24 03:36:51 +00:00
feat: update app to check for updates on app open
This commit is contained in:
@@ -158,7 +158,7 @@ class TvActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
LaunchedEffect(updateViewModel) {
|
||||
updateViewModel.checkForUpdates(showUpToDateMessage = false)
|
||||
updateViewModel.checkForUpdatesOnAppOpen()
|
||||
}
|
||||
|
||||
LaunchedEffect(updateViewModel, context) {
|
||||
|
||||
@@ -59,6 +59,10 @@ fun AppScreen(
|
||||
onPauseOrDispose { }
|
||||
}
|
||||
|
||||
LaunchedEffect(updateViewModel) {
|
||||
updateViewModel.checkForUpdatesOnAppOpen()
|
||||
}
|
||||
|
||||
LaunchedEffect(updateViewModel) {
|
||||
updateViewModel.snackbarMessages.collect { message ->
|
||||
snackbarHostState.showSnackbar(message)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,12 @@ class AppUpdateViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun checkForUpdatesOnAppOpen() {
|
||||
viewModelScope.launch {
|
||||
appUpdateController.checkForUpdatesOnAppOpen()
|
||||
}
|
||||
}
|
||||
|
||||
fun acceptUpdate() {
|
||||
viewModelScope.launch {
|
||||
appUpdateController.installAvailableUpdate()
|
||||
|
||||
Reference in New Issue
Block a user