diff --git a/android/src/main/kotlin/ca/gosyer/jui/android/data/update/UpdateCheckWorker.kt b/android/src/main/kotlin/ca/gosyer/jui/android/data/update/UpdateCheckWorker.kt index 6e7378c7..7c01bb82 100644 --- a/android/src/main/kotlin/ca/gosyer/jui/android/data/update/UpdateCheckWorker.kt +++ b/android/src/main/kotlin/ca/gosyer/jui/android/data/update/UpdateCheckWorker.kt @@ -31,7 +31,7 @@ class UpdateCheckWorker(private val context: Context, workerParams: WorkerParame .let { if (it.updatePreferences.enabled().get()) { it.updateChecker - .checkForUpdates() + .checkForUpdates(false) .singleOrNull() } else null } diff --git a/data/src/commonMain/kotlin/ca/gosyer/jui/data/update/UpdateChecker.kt b/data/src/commonMain/kotlin/ca/gosyer/jui/data/update/UpdateChecker.kt index 345de622..3531624b 100644 --- a/data/src/commonMain/kotlin/ca/gosyer/jui/data/update/UpdateChecker.kt +++ b/data/src/commonMain/kotlin/ca/gosyer/jui/data/update/UpdateChecker.kt @@ -21,8 +21,8 @@ class UpdateChecker @Inject constructor( private val updatePreferences: UpdatePreferences, private val client: Http ) { - fun checkForUpdates() = flow { - // if (!updatePreferences.enabled().get()) return + fun checkForUpdates(manualFetch: Boolean) = flow { + if (!manualFetch && !updatePreferences.enabled().get()) return@flow val latestRelease = client.get( "https://api.github.com/repos/$GITHUB_REPO/releases/latest" ).body() diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/AboutViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/AboutViewModel.kt index be3931ef..4458e83b 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/AboutViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/AboutViewModel.kt @@ -62,7 +62,7 @@ class AboutViewModel @Inject constructor( } fun checkForUpdates() { - updateChecker.checkForUpdates() + updateChecker.checkForUpdates(true) .filterIsInstance() .onEach { _updates.emit(it) diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/main/components/Tray.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/main/components/Tray.kt index d83f3332..36d1c850 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/main/components/Tray.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/main/components/Tray.kt @@ -40,7 +40,7 @@ fun ApplicationScope.Tray(icon: Painter) { trayState.sendNotification( Notification( MR.strings.new_update_title.localized(), - MR.strings.new_update_message.localized(Locale.getDefault(), it.version), + MR.strings.new_update_message.localized(Locale.getDefault(), it.release.version), Notification.Type.Info ) ) diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/main/components/TrayViewModel.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/main/components/TrayViewModel.kt index 87f43428..3183a136 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/main/components/TrayViewModel.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/main/components/TrayViewModel.kt @@ -7,39 +7,25 @@ package ca.gosyer.jui.ui.main.components import ca.gosyer.jui.data.update.UpdateChecker -import ca.gosyer.jui.data.update.UpdatePreferences -import ca.gosyer.jui.data.update.model.GithubRelease import ca.gosyer.jui.uicore.vm.ContextWrapper import ca.gosyer.jui.uicore.vm.ViewModel import kotlinx.coroutines.MainScope import kotlinx.coroutines.cancel -import kotlinx.coroutines.flow.MutableSharedFlow -import kotlinx.coroutines.flow.asSharedFlow -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.filterIsInstance +import kotlinx.coroutines.flow.shareIn import me.tatarka.inject.annotations.Inject class TrayViewModel @Inject constructor( updateChecker: UpdateChecker, - updatePreferences: UpdatePreferences, contextWrapper: ContextWrapper ) : ViewModel(contextWrapper) { override val scope = MainScope() - private val _updateFound = MutableSharedFlow() - val updateFound = _updateFound.asSharedFlow() - - init { - if (updatePreferences.enabled().get()) { - updateChecker.checkForUpdates() - .onEach { - if (it is UpdateChecker.Update.UpdateFound) { - _updateFound.emit(it.release) - } - } - .launchIn(scope) - } - } + val updateFound = updateChecker + .checkForUpdates(false) + .filterIsInstance() + .shareIn(scope, SharingStarted.Eagerly, 1) override fun onDispose() { super.onDispose()