Revert "Use app scoped CoroutineScope (#3403)"

This reverts commit 509eee5dfb.

Fixes #3429
This commit is contained in:
AntsyLich
2026-06-18 17:31:52 +06:00
parent ee6a9876ec
commit 80541831bb
17 changed files with 96 additions and 87 deletions
@@ -286,7 +286,7 @@ class ReaderViewModel @JvmOverloads constructor(
val context = Injekt.get<Application>()
val source = sourceManager.getOrStub(manga.source)
loader = ChapterLoader(context, viewModelScope, downloadManager, downloadProvider, manga, source)
loader = ChapterLoader(context, downloadManager, downloadProvider, manga, source)
loadChapter(loader!!, chapterList.first { chapterId == it.chapter.id })
Result.success(true)
@@ -6,7 +6,6 @@ import eu.kanade.tachiyomi.data.download.DownloadProvider
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
import kotlinx.coroutines.CoroutineScope
import mihon.core.archive.archiveReader
import mihon.core.archive.epubReader
import tachiyomi.core.common.i18n.stringResource
@@ -23,7 +22,6 @@ import tachiyomi.source.local.io.Format
*/
class ChapterLoader(
private val context: Context,
private val scope: CoroutineScope,
private val downloadManager: DownloadManager,
private val downloadProvider: DownloadProvider,
private val manga: Manga,
@@ -102,7 +100,7 @@ class ChapterLoader(
is Format.Epub -> EpubPageLoader(format.file.epubReader(context))
}
}
source is HttpSource -> HttpPageLoader(chapter, source, scope)
source is HttpSource -> HttpPageLoader(chapter, source)
source is StubSource -> error(context.stringResource(MR.strings.source_not_installed, source.toString()))
else -> error(context.stringResource(MR.strings.loader_not_implemented_error))
}
@@ -8,8 +8,9 @@ import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.runInterruptible
@@ -30,10 +31,11 @@ import kotlin.math.min
internal class HttpPageLoader(
private val chapter: ReaderChapter,
private val source: HttpSource,
scope: CoroutineScope,
private val chapterCache: ChapterCache = Injekt.get(),
) : PageLoader() {
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
/**
* A queue used to manage requests one by one while allowing priorities.
*/
@@ -122,14 +124,14 @@ internal class HttpPageLoader(
queue.offer(PriorityPage(page, PriorityPage.RETRY))
}
@OptIn(DelicateCoroutinesApi::class)
override fun recycle() {
super.recycle()
scope.cancel()
queue.clear()
// Cache current page list progress for online chapters to allow a faster reopen
chapter.pages?.let { pages ->
GlobalScope.launchIO {
launchIO {
try {
// Convert to pages without reader information
val pagesToSave = pages.map { Page(it.index, it.url, it.imageUrl) }