Use an app scoped CoroutineScope
Replaces the eight ad hoc application lifetime scopes and the GlobalScope launchUI/launchIO/launchNow helpers with a single injected CoroutineScope(SupervisorJob() + Dispatchers.IO), qualified by @AppCoroutineScope. Every scope this replaces was already on IO, or named IO explicitly, so call sites keep their dispatcher. The two that need the main thread use scope.launchUI. Scopes with a real cancellation point keep their own: HttpPageLoader, ShizukuInstaller and the reader viewers. Only HttpPageLoader's page list cache save moves to the app scope, since it runs after recycle() has cancelled the loader's own scope. NotificationReceiver now holds the broadcast open with goAsync() while its work runs, so the process isn't torn down mid update. This reverts the revert of #3403. It was reverted for #3429, where restore() dropped every download because SourceManager.get() returned null until the extensions had loaded. That surface suspends since #3869, so the race is gone.
This commit is contained in:
@@ -17,7 +17,6 @@ import eu.kanade.tachiyomi.util.system.toast
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
@@ -33,6 +32,7 @@ import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import logcat.LogPriority
|
||||
import mihon.core.metro.AppCoroutineScope
|
||||
import mihon.domain.extension.interactor.UpdateExtensionStores
|
||||
import mihon.domain.extension.model.ExtensionStore
|
||||
import mihon.domain.extension.repository.ExtensionStoreRepository
|
||||
@@ -53,6 +53,7 @@ import java.util.Locale
|
||||
@Inject
|
||||
@SingleIn(AppScope::class)
|
||||
class ExtensionManager(
|
||||
@AppCoroutineScope private val scope: CoroutineScope,
|
||||
private val context: Context,
|
||||
private val preferences: SourcePreferences,
|
||||
private val trustExtension: TrustExtension,
|
||||
@@ -62,8 +63,6 @@ class ExtensionManager(
|
||||
private val extensionUpdateNotifier: ExtensionUpdateNotifier,
|
||||
) {
|
||||
|
||||
val scope = CoroutineScope(SupervisorJob())
|
||||
|
||||
private val initialized = CompletableDeferred<Unit>()
|
||||
|
||||
private val iconMap = mutableMapOf<String, Drawable>()
|
||||
@@ -96,7 +95,7 @@ class ExtensionManager(
|
||||
init {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
loadExtensions()
|
||||
ExtensionInstallReceiver(InstallationListener()).register(context)
|
||||
ExtensionInstallReceiver(InstallationListener(), scope).register(context)
|
||||
|
||||
// Everything the load decision rests on can change while running, so decide again
|
||||
merge(
|
||||
|
||||
Reference in New Issue
Block a user