Revert "Use app scoped CoroutineScope (#3403)"
This reverts commit 509eee5dfb.
Fixes #3429
This commit is contained in:
@@ -5,14 +5,16 @@ import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import tachiyomi.core.common.util.lang.launchIO
|
||||
import tachiyomi.domain.source.model.StubSource
|
||||
import tachiyomi.domain.source.repository.StubSourceRepository
|
||||
import tachiyomi.domain.source.service.SourceManager
|
||||
@@ -24,7 +26,6 @@ import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class AndroidSourceManager(
|
||||
private val context: Context,
|
||||
private val scope: CoroutineScope,
|
||||
private val extensionManager: ExtensionManager,
|
||||
private val sourceRepository: StubSourceRepository,
|
||||
) : SourceManager {
|
||||
@@ -34,6 +35,8 @@ class AndroidSourceManager(
|
||||
|
||||
private val downloadManager: DownloadManager by injectLazy()
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.IO)
|
||||
|
||||
private val sourcesMapFlow = MutableStateFlow(ConcurrentHashMap<Long, Source>())
|
||||
|
||||
private val stubSourcesMap = ConcurrentHashMap<Long, StubSource>()
|
||||
@@ -41,7 +44,7 @@ class AndroidSourceManager(
|
||||
override val sources: Flow<List<Source>> = sourcesMapFlow.map { it.values.toList() }
|
||||
|
||||
init {
|
||||
scope.launchIO {
|
||||
scope.launch {
|
||||
extensionManager.installedExtensionsFlow
|
||||
.collectLatest { extensions ->
|
||||
val mutableMap = ConcurrentHashMap<Long, Source>(
|
||||
@@ -64,7 +67,7 @@ class AndroidSourceManager(
|
||||
}
|
||||
}
|
||||
|
||||
scope.launchIO {
|
||||
scope.launch {
|
||||
sourceRepository.subscribeAll()
|
||||
.collectLatest { sources ->
|
||||
val mutableMap = stubSourcesMap.toMutableMap()
|
||||
@@ -95,9 +98,9 @@ class AndroidSourceManager(
|
||||
}
|
||||
|
||||
private fun registerStubSource(source: StubSource) {
|
||||
scope.launchIO {
|
||||
scope.launch {
|
||||
val dbSource = sourceRepository.getStubSource(source.id)
|
||||
if (dbSource == source) return@launchIO
|
||||
if (dbSource == source) return@launch
|
||||
sourceRepository.upsertStubSource(source.id, source.lang, source.name)
|
||||
if (dbSource != null) {
|
||||
downloadManager.renameSource(dbSource, source)
|
||||
|
||||
Reference in New Issue
Block a user