mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-23 21:12: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 {
|
.let {
|
||||||
if (it.updatePreferences.enabled().get()) {
|
if (it.updatePreferences.enabled().get()) {
|
||||||
it.updateChecker
|
it.updateChecker
|
||||||
.checkForUpdates()
|
.checkForUpdates(false)
|
||||||
.singleOrNull()
|
.singleOrNull()
|
||||||
} else null
|
} else null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ class UpdateChecker @Inject constructor(
|
|||||||
private val updatePreferences: UpdatePreferences,
|
private val updatePreferences: UpdatePreferences,
|
||||||
private val client: Http
|
private val client: Http
|
||||||
) {
|
) {
|
||||||
fun checkForUpdates() = flow {
|
fun checkForUpdates(manualFetch: Boolean) = flow {
|
||||||
// if (!updatePreferences.enabled().get()) return
|
if (!manualFetch && !updatePreferences.enabled().get()) return@flow
|
||||||
val latestRelease = client.get(
|
val latestRelease = client.get(
|
||||||
"https://api.github.com/repos/$GITHUB_REPO/releases/latest"
|
"https://api.github.com/repos/$GITHUB_REPO/releases/latest"
|
||||||
).body<GithubRelease>()
|
).body<GithubRelease>()
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class AboutViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun checkForUpdates() {
|
fun checkForUpdates() {
|
||||||
updateChecker.checkForUpdates()
|
updateChecker.checkForUpdates(true)
|
||||||
.filterIsInstance<Update.UpdateFound>()
|
.filterIsInstance<Update.UpdateFound>()
|
||||||
.onEach {
|
.onEach {
|
||||||
_updates.emit(it)
|
_updates.emit(it)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ fun ApplicationScope.Tray(icon: Painter) {
|
|||||||
trayState.sendNotification(
|
trayState.sendNotification(
|
||||||
Notification(
|
Notification(
|
||||||
MR.strings.new_update_title.localized(),
|
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
|
Notification.Type.Info
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,39 +7,25 @@
|
|||||||
package ca.gosyer.jui.ui.main.components
|
package ca.gosyer.jui.ui.main.components
|
||||||
|
|
||||||
import ca.gosyer.jui.data.update.UpdateChecker
|
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.ContextWrapper
|
||||||
import ca.gosyer.jui.uicore.vm.ViewModel
|
import ca.gosyer.jui.uicore.vm.ViewModel
|
||||||
import kotlinx.coroutines.MainScope
|
import kotlinx.coroutines.MainScope
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.asSharedFlow
|
import kotlinx.coroutines.flow.filterIsInstance
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.shareIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
|
||||||
import me.tatarka.inject.annotations.Inject
|
import me.tatarka.inject.annotations.Inject
|
||||||
|
|
||||||
class TrayViewModel @Inject constructor(
|
class TrayViewModel @Inject constructor(
|
||||||
updateChecker: UpdateChecker,
|
updateChecker: UpdateChecker,
|
||||||
updatePreferences: UpdatePreferences,
|
|
||||||
contextWrapper: ContextWrapper
|
contextWrapper: ContextWrapper
|
||||||
) : ViewModel(contextWrapper) {
|
) : ViewModel(contextWrapper) {
|
||||||
override val scope = MainScope()
|
override val scope = MainScope()
|
||||||
|
|
||||||
private val _updateFound = MutableSharedFlow<GithubRelease>()
|
val updateFound = updateChecker
|
||||||
val updateFound = _updateFound.asSharedFlow()
|
.checkForUpdates(false)
|
||||||
|
.filterIsInstance<UpdateChecker.Update.UpdateFound>()
|
||||||
init {
|
.shareIn(scope, SharingStarted.Eagerly, 1)
|
||||||
if (updatePreferences.enabled().get()) {
|
|
||||||
updateChecker.checkForUpdates()
|
|
||||||
.onEach {
|
|
||||||
if (it is UpdateChecker.Update.UpdateFound) {
|
|
||||||
_updateFound.emit(it.release)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.launchIn(scope)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDispose() {
|
override fun onDispose() {
|
||||||
super.onDispose()
|
super.onDispose()
|
||||||
|
|||||||
Reference in New Issue
Block a user