Fix local source cover updating

Ref: tachiyomiorg/tachiyomi#10186
This commit is contained in:
FooIbar 2024-01-16 21:34:34 +08:00
parent 139663acfc
commit a88422752b
2 changed files with 35 additions and 12 deletions

View File

@ -18,6 +18,7 @@ import eu.kanade.domain.manga.interactor.GetExcludedScanlators
import eu.kanade.domain.manga.interactor.SetExcludedScanlators
import eu.kanade.domain.manga.interactor.UpdateManga
import eu.kanade.domain.manga.model.chaptersFiltered
import eu.kanade.domain.manga.model.copyFrom
import eu.kanade.domain.manga.model.downloadedFilter
import eu.kanade.domain.manga.model.toSManga
import eu.kanade.domain.track.interactor.AddTracks
@ -227,11 +228,18 @@ class MangaScreenModel(
// Fetch info-chapters when needed
if (screenModelScope.isActive) {
val fetchFromSourceTasks = listOf(
async { if (needRefreshInfo) fetchMangaFromSource() },
async { if (needRefreshChapter) fetchChaptersFromSource() },
)
fetchFromSourceTasks.awaitAll()
if (source?.isLocal() == true) {
// `fetchChaptersFromSource` should be called before `fetchMangaFromSource`
// because `LocalSource.getChapterList` has side effects since 82bdf63
if (needRefreshChapter) fetchChaptersFromSource()
if (needRefreshInfo) fetchMangaFromSource()
} else {
val fetchFromSourceTasks = listOf(
async { if (needRefreshInfo) fetchMangaFromSource() },
async { if (needRefreshChapter) fetchChaptersFromSource() },
)
fetchFromSourceTasks.awaitAll()
}
}
// Initial loading finished
@ -242,11 +250,18 @@ class MangaScreenModel(
fun fetchAllFromSource(manualFetch: Boolean = true) {
screenModelScope.launch {
updateSuccessState { it.copy(isRefreshingData = true) }
val fetchFromSourceTasks = listOf(
async { fetchMangaFromSource(manualFetch) },
async { fetchChaptersFromSource(manualFetch) },
)
fetchFromSourceTasks.awaitAll()
if (source?.isLocal() == true) {
// `fetchChaptersFromSource` should be called before `fetchMangaFromSource`
// because `LocalSource.getChapterList` has side effects since 82bdf63
fetchChaptersFromSource(manualFetch)
fetchMangaFromSource(manualFetch)
} else {
val fetchFromSourceTasks = listOf(
async { fetchMangaFromSource(manualFetch) },
async { fetchChaptersFromSource(manualFetch) },
)
fetchFromSourceTasks.awaitAll()
}
updateSuccessState { it.copy(isRefreshingData = false) }
}
}
@ -537,7 +552,13 @@ class MangaScreenModel(
val state = successState ?: return
try {
withIOContext {
val chapters = state.source.getChapterList(state.manga.toSManga())
val manga = state.manga.toSManga()
val chapters = state.source.getChapterList(manga)
// `LocalSource.getChapterList` has side effects since 82bdf63
if (state.source.isLocal()) {
updateSuccessState { it.copy(manga = it.manga.copyFrom(manga)) }
}
val newChapters = syncChaptersWithSource.await(
chapters,

View File

@ -1,6 +1,7 @@
package tachiyomi.source.local
import android.content.Context
import androidx.core.net.toUri
import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.Source
@ -285,7 +286,8 @@ actual class LocalSource(
}
// Copy the cover from the first chapter found if not available
if (manga.thumbnail_url.isNullOrBlank()) {
val cover = UniFile.fromUri(context, manga.thumbnail_url?.toUri())
if (cover?.let { ImageUtil.isImage(it.name) { it.openInputStream() } } != true) {
chapters.lastOrNull()?.let { chapter ->
updateCover(chapter, manga)
}