mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-22 20:42:34 +01:00
Check run updater preference in action
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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<GithubRelease>()
|
||||
|
||||
@@ -62,7 +62,7 @@ class AboutViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun checkForUpdates() {
|
||||
updateChecker.checkForUpdates()
|
||||
updateChecker.checkForUpdates(true)
|
||||
.filterIsInstance<Update.UpdateFound>()
|
||||
.onEach {
|
||||
_updates.emit(it)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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<GithubRelease>()
|
||||
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<UpdateChecker.Update.UpdateFound>()
|
||||
.shareIn(scope, SharingStarted.Eagerly, 1)
|
||||
|
||||
override fun onDispose() {
|
||||
super.onDispose()
|
||||
|
||||
Reference in New Issue
Block a user