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) {
|
LaunchedEffect(updateViewModel) {
|
||||||
updateViewModel.checkForUpdates(showUpToDateMessage = false)
|
updateViewModel.checkForUpdatesOnAppOpen()
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(updateViewModel, context) {
|
LaunchedEffect(updateViewModel, context) {
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ fun AppScreen(
|
|||||||
onPauseOrDispose { }
|
onPauseOrDispose { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(updateViewModel) {
|
||||||
|
updateViewModel.checkForUpdatesOnAppOpen()
|
||||||
|
}
|
||||||
|
|
||||||
LaunchedEffect(updateViewModel) {
|
LaunchedEffect(updateViewModel) {
|
||||||
updateViewModel.snackbarMessages.collect { message ->
|
updateViewModel.snackbarMessages.collect { message ->
|
||||||
snackbarHostState.showSnackbar(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.LocalMediaRepository
|
||||||
import hu.bbara.purefin.core.data.UserSessionRepository
|
import hu.bbara.purefin.core.data.UserSessionRepository
|
||||||
import hu.bbara.purefin.core.download.MediaDownloadController
|
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.jellyfin.JellyfinMediaMetadataUpdater
|
||||||
import hu.bbara.purefin.core.model.EpisodeUiModel
|
import hu.bbara.purefin.core.model.EpisodeUiModel
|
||||||
import hu.bbara.purefin.core.model.LibraryUiModel
|
import hu.bbara.purefin.core.model.LibraryUiModel
|
||||||
@@ -41,7 +40,6 @@ class AppViewModel @Inject constructor(
|
|||||||
private val jellyfinMediaMetadataUpdater: JellyfinMediaMetadataUpdater,
|
private val jellyfinMediaMetadataUpdater: JellyfinMediaMetadataUpdater,
|
||||||
private val navigationManager: NavigationManager,
|
private val navigationManager: NavigationManager,
|
||||||
private val mediaDownloadManager: MediaDownloadController,
|
private val mediaDownloadManager: MediaDownloadController,
|
||||||
private val appUpdateController: AppUpdateController,
|
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _isRefreshing = MutableStateFlow(false)
|
private val _isRefreshing = MutableStateFlow(false)
|
||||||
@@ -241,10 +239,6 @@ class AppViewModel @Inject constructor(
|
|||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
homeRepository.refreshHomeData()
|
homeRepository.refreshHomeData()
|
||||||
appUpdateController.checkForUpdates(
|
|
||||||
showUpToDateMessage = false,
|
|
||||||
showFailureMessage = false
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// Refresh is best-effort; don't crash on failure
|
// Refresh is best-effort; don't crash on failure
|
||||||
}
|
}
|
||||||
@@ -261,10 +255,6 @@ class AppViewModel @Inject constructor(
|
|||||||
_isRefreshing.value = true
|
_isRefreshing.value = true
|
||||||
try {
|
try {
|
||||||
homeRepository.refreshHomeData()
|
homeRepository.refreshHomeData()
|
||||||
appUpdateController.checkForUpdates(
|
|
||||||
showUpToDateMessage = false,
|
|
||||||
showFailureMessage = false
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// Refresh is best-effort; don't crash on failure
|
// Refresh is best-effort; don't crash on failure
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -34,11 +34,13 @@ class AppUpdateController @Inject constructor(
|
|||||||
|
|
||||||
private val checkMutex = Mutex()
|
private val checkMutex = Mutex()
|
||||||
private val installMutex = Mutex()
|
private val installMutex = Mutex()
|
||||||
|
private var checkedForUpdatesOnAppOpen = false
|
||||||
|
|
||||||
override val settingGroups: Flow<List<SettingGroup>> = availableUpdate
|
override val settingGroups: Flow<List<SettingGroup>> = availableUpdate
|
||||||
.map { update ->
|
.map { update ->
|
||||||
val options = listOfNotNull<SettingOption<*>>(
|
val options = listOfNotNull<SettingOption<*>>(
|
||||||
buildNumberSetting(),
|
buildNumberSetting(),
|
||||||
|
checkForUpdatesSetting(),
|
||||||
update?.let { installUpdateSetting(it) }
|
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() {
|
suspend fun installAvailableUpdate() {
|
||||||
val update = _availableUpdate.value ?: return
|
val update = _availableUpdate.value ?: return
|
||||||
if (!installMutex.tryLock()) {
|
if (!installMutex.tryLock()) {
|
||||||
@@ -110,8 +124,15 @@ class AppUpdateController @Inject constructor(
|
|||||||
value = appVersionProvider.versionCode.toString()
|
value = appVersionProvider.versionCode.toString()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private fun checkForUpdatesSetting() = VoidSetting(
|
||||||
|
key = CHECK_FOR_UPDATES_KEY,
|
||||||
|
title = "Check for updates",
|
||||||
|
onClick = { checkForUpdates() }
|
||||||
|
)
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
const val BUILD_NUMBER_KEY = "build_number"
|
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"
|
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() {
|
fun acceptUpdate() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
appUpdateController.installAvailableUpdate()
|
appUpdateController.installAvailableUpdate()
|
||||||
|
|||||||
Reference in New Issue
Block a user