Subscribe gallerysite changes

This commit is contained in:
tarsin committed 2023-06-07 15:02:24 +08:00
1 parent 797d511c2c
commit 431007a731
2 files changed
+13 -2

No files matched your search

@@ -27,7 +27,7 @@ object Settings : DataStorePreferences(null) {
var favCount by intArrayPref("fav_count", 10)
var archivePasswds by stringSetOrNullPref("archive_passwds")
var downloadDelay by intFromStrPref("download_delay", 0)
var gallerySite by intFromStrPref("gallery_site", 0)
var gallerySite by intFromStrPref("gallery_site", 0).observed { updateWhenGallerySiteChanges() }
var multiThreadDownload by intFromStrPref("download_thread", 3)
var preloadImage by intFromStrPref("preload_image", 5)
var theme by intFromStrPref("theme", -1).observed { updateWhenThemeChanges() }
@@ -2,6 +2,7 @@ package com.hippo.ehviewer
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
import com.hippo.ehviewer.client.EhEngine
import com.hippo.ehviewer.dailycheck.updateDailyCheckWork
import com.hippo.ehviewer.ui.keepNoMediaFileStatus
import eu.kanade.tachiyomi.util.lang.launchIO
@@ -13,7 +14,7 @@ import kotlinx.coroutines.launch
import splitties.init.appCtx
import splitties.preferences.PrefDelegate
val collectScope = CoroutineScope(Dispatchers.Main + SupervisorJob())
private val collectScope = CoroutineScope(Dispatchers.Main + SupervisorJob())
fun <T, R : PrefDelegate<T>> R.observed(func: (Unit) -> Unit) = apply { collectScope.launch { changesFlow().collect(func) } }
fun <T, R : Settings.Delegate<T>> R.observed(func: (Unit) -> Unit) = apply { collectScope.launch { flowGetter().collect(func) } }
@@ -44,3 +45,13 @@ fun updateWhenThemeChanges() {
fun updateWhenRequestNewsChanges() {
updateDailyCheckWork(appCtx)
}
fun updateWhenGallerySiteChanges() {
collectScope.launchIO {
runCatching {
EhEngine.getUConfig()
}.onFailure {
it.printStackTrace()
}
}
}