From fd5d568a104cc3825f5e62c441e1471ddcc378bb Mon Sep 17 00:00:00 2001 From: Secozzi Date: Tue, 2 Jul 2024 13:19:38 +0200 Subject: [PATCH] Fix multiple issues regarding sources loading too late Co-authored-by: jobobby04 <17078382+jobobby04@users.noreply.github.com> Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> --- .../java/eu/kanade/core/util/AnimeSourceUtil.kt | 13 +++++++++++++ .../java/eu/kanade/core/util/MangaSourceUtil.kt | 13 +++++++++++++ .../data/download/anime/AnimeDownloadCache.kt | 17 ++++++----------- .../data/download/manga/MangaDownloadCache.kt | 17 ++++++----------- .../extension/anime/AnimeExtensionManager.kt | 7 ++++--- .../extension/manga/MangaExtensionManager.kt | 8 ++++---- .../source/anime/AndroidAnimeSourceManager.kt | 7 +++++++ .../source/manga/AndroidMangaSourceManager.kt | 7 +++++++ .../details/AnimeSourcePreferencesScreen.kt | 7 +++++++ .../migration/search/AnimeSourceSearchScreen.kt | 7 +++++++ .../source/browse/BrowseAnimeSourceScreen.kt | 7 +++++++ .../globalsearch/GlobalAnimeSearchScreen.kt | 6 ++++++ .../details/MangaSourcePreferencesScreen.kt | 7 +++++++ .../migration/search/MangaSourceSearchScreen.kt | 7 +++++++ .../source/browse/BrowseMangaSourceScreen.kt | 7 +++++++ .../globalsearch/GlobalMangaSearchScreen.kt | 6 ++++++ .../tachiyomi/ui/entries/anime/AnimeScreen.kt | 6 ++++++ .../tachiyomi/ui/entries/manga/MangaScreen.kt | 6 ++++++ .../tachiyomi/ui/player/PlayerViewModel.kt | 2 ++ .../tachiyomi/ui/reader/ReaderActivity.kt | 5 +++++ .../tachiyomi/ui/reader/ReaderViewModel.kt | 2 ++ .../source/anime/service/AnimeSourceManager.kt | 3 +++ .../source/manga/service/MangaSourceManager.kt | 3 +++ 23 files changed, 141 insertions(+), 29 deletions(-) create mode 100644 app/src/main/java/eu/kanade/core/util/AnimeSourceUtil.kt create mode 100644 app/src/main/java/eu/kanade/core/util/MangaSourceUtil.kt diff --git a/app/src/main/java/eu/kanade/core/util/AnimeSourceUtil.kt b/app/src/main/java/eu/kanade/core/util/AnimeSourceUtil.kt new file mode 100644 index 000000000..d72523824 --- /dev/null +++ b/app/src/main/java/eu/kanade/core/util/AnimeSourceUtil.kt @@ -0,0 +1,13 @@ +package eu.kanade.core.util + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.remember +import tachiyomi.domain.source.anime.service.AnimeSourceManager +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get + +@Composable +fun ifAnimeSourcesLoaded(): Boolean { + return remember { Injekt.get().isInitialized }.collectAsState().value +} diff --git a/app/src/main/java/eu/kanade/core/util/MangaSourceUtil.kt b/app/src/main/java/eu/kanade/core/util/MangaSourceUtil.kt new file mode 100644 index 000000000..4f3959367 --- /dev/null +++ b/app/src/main/java/eu/kanade/core/util/MangaSourceUtil.kt @@ -0,0 +1,13 @@ +package eu.kanade.core.util + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.remember +import tachiyomi.domain.source.manga.service.MangaSourceManager +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get + +@Composable +fun ifMangaSourcesLoaded(): Boolean { + return remember { Injekt.get().isInitialized }.collectAsState().value +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/anime/AnimeDownloadCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/anime/AnimeDownloadCache.kt index 6d413653a..a6dc27205 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/anime/AnimeDownloadCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/anime/AnimeDownloadCache.kt @@ -16,6 +16,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.debounce +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onStart @@ -318,18 +319,12 @@ class AnimeDownloadCache( } // Try to wait until extensions and sources have loaded - var sources = getSources() - if (sources.isEmpty()) { - withTimeoutOrNull(30.seconds) { - while (!extensionManager.isInitialized) { - delay(2.seconds) - } + var sources = emptyList() + withTimeoutOrNull(30.seconds) { + extensionManager.isInitialized.first { it } + sourceManager.isInitialized.first { it } - while (extensionManager.availableExtensionsFlow.value.isNotEmpty() && sources.isEmpty()) { - delay(2.seconds) - sources = getSources() - } - } + sources = getSources() } val sourceMap = sources.associate { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/manga/MangaDownloadCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/manga/MangaDownloadCache.kt index 113c8e142..e017eda73 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/manga/MangaDownloadCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/manga/MangaDownloadCache.kt @@ -19,6 +19,7 @@ import kotlinx.coroutines.ensureActive import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.debounce +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onStart @@ -342,18 +343,12 @@ class MangaDownloadCache( } // Try to wait until extensions and sources have loaded - var sources = getSources() - if (sources.isEmpty()) { - withTimeoutOrNull(30.seconds) { - while (!extensionManager.isInitialized) { - delay(2.seconds) - } + var sources = emptyList() + withTimeoutOrNull(30.seconds) { + extensionManager.isInitialized.first { it } + sourceManager.isInitialized.first { it } - while (extensionManager.availableExtensionsFlow.value.isNotEmpty() && sources.isEmpty()) { - delay(2.seconds) - sources = getSources() - } - } + sources = getSources() } val sourceMap = sources.associate { provider.getSourceDirName(it).lowercase() to it.id } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/anime/AnimeExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/anime/AnimeExtensionManager.kt index e5a555602..e2bf60793 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/anime/AnimeExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/anime/AnimeExtensionManager.kt @@ -16,6 +16,7 @@ import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.async import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.emptyFlow import logcat.LogPriority @@ -44,8 +45,8 @@ class AnimeExtensionManager( private val trustExtension: TrustAnimeExtension = Injekt.get(), ) { - var isInitialized = false - private set + private val _isInitialized = MutableStateFlow(false) + val isInitialized: StateFlow = _isInitialized.asStateFlow() /** * API where all the available anime extensions can be found. @@ -119,7 +120,7 @@ class AnimeExtensionManager( .filterIsInstance() .map { it.extension } - isInitialized = true + _isInitialized.value = true } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/manga/MangaExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/manga/MangaExtensionManager.kt index cd854a247..e1bd67ff5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/manga/MangaExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/manga/MangaExtensionManager.kt @@ -16,10 +16,10 @@ import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.async import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.emptyFlow import logcat.LogPriority -import tachiyomi.core.common.preference.plusAssign import tachiyomi.core.common.util.lang.launchNow import tachiyomi.core.common.util.lang.withUIContext import tachiyomi.core.common.util.system.logcat @@ -42,8 +42,8 @@ class MangaExtensionManager( private val trustExtension: TrustMangaExtension = Injekt.get(), ) { - var isInitialized = false - private set + private val _isInitialized = MutableStateFlow(false) + val isInitialized: StateFlow = _isInitialized.asStateFlow() /** * API where all the available extensions can be found. @@ -109,7 +109,7 @@ class MangaExtensionManager( .filterIsInstance() .map { it.extension } - isInitialized = true + _isInitialized.value = true } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/anime/AndroidAnimeSourceManager.kt b/app/src/main/java/eu/kanade/tachiyomi/source/anime/AndroidAnimeSourceManager.kt index 6d3e11960..12ea7dc6f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/anime/AndroidAnimeSourceManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/anime/AndroidAnimeSourceManager.kt @@ -11,6 +11,8 @@ 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 @@ -29,6 +31,10 @@ class AndroidAnimeSourceManager( private val extensionManager: AnimeExtensionManager, private val sourceRepository: AnimeStubSourceRepository, ) : AnimeSourceManager { + + private val _isInitialized = MutableStateFlow(false) + override val isInitialized: StateFlow = _isInitialized.asStateFlow() + private val downloadManager: AnimeDownloadManager by injectLazy() private val scope = CoroutineScope(Job() + Dispatchers.IO) @@ -61,6 +67,7 @@ class AndroidAnimeSourceManager( } } sourcesMapFlow.value = mutableMap + _isInitialized.value = true } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/manga/AndroidMangaSourceManager.kt b/app/src/main/java/eu/kanade/tachiyomi/source/manga/AndroidMangaSourceManager.kt index c66e32f2a..d2d45d33a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/manga/AndroidMangaSourceManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/manga/AndroidMangaSourceManager.kt @@ -11,6 +11,8 @@ 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 @@ -29,6 +31,10 @@ class AndroidMangaSourceManager( private val extensionManager: MangaExtensionManager, private val sourceRepository: MangaStubSourceRepository, ) : MangaSourceManager { + + private val _isInitialized = MutableStateFlow(false) + override val isInitialized: StateFlow = _isInitialized.asStateFlow() + private val downloadManager: MangaDownloadManager by injectLazy() private val scope = CoroutineScope(Job() + Dispatchers.IO) @@ -61,6 +67,7 @@ class AndroidMangaSourceManager( } } sourcesMapFlow.value = mutableMap + _isInitialized.value = true } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/extension/details/AnimeSourcePreferencesScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/extension/details/AnimeSourcePreferencesScreen.kt index 15946e814..e4756ede6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/extension/details/AnimeSourcePreferencesScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/extension/details/AnimeSourcePreferencesScreen.kt @@ -31,6 +31,7 @@ import androidx.preference.forEach import androidx.preference.getOnBindEditTextListener import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.core.util.ifAnimeSourcesLoaded import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.util.Screen import eu.kanade.tachiyomi.R @@ -40,6 +41,7 @@ import eu.kanade.tachiyomi.data.preference.SharedPreferencesDataStore import eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText.Companion.setIncognito import tachiyomi.domain.source.anime.service.AnimeSourceManager import tachiyomi.presentation.core.components.material.Scaffold +import tachiyomi.presentation.core.screens.LoadingScreen import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -47,6 +49,11 @@ class AnimeSourcePreferencesScreen(val sourceId: Long) : Screen() { @Composable override fun Content() { + if (!ifAnimeSourcesLoaded()) { + LoadingScreen() + return + } + val context = LocalContext.current val navigator = LocalNavigator.currentOrThrow diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/migration/search/AnimeSourceSearchScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/migration/search/AnimeSourceSearchScreen.kt index 3034421d4..ad661c068 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/migration/search/AnimeSourceSearchScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/migration/search/AnimeSourceSearchScreen.kt @@ -18,6 +18,7 @@ import androidx.paging.compose.collectAsLazyPagingItems import cafe.adriel.voyager.core.model.rememberScreenModel import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.core.util.ifAnimeSourcesLoaded import eu.kanade.presentation.browse.anime.BrowseAnimeSourceContent import eu.kanade.presentation.components.SearchToolbar import eu.kanade.presentation.util.Screen @@ -34,6 +35,7 @@ import tachiyomi.i18n.MR import tachiyomi.presentation.core.components.material.ExtendedFloatingActionButton import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.i18n.stringResource +import tachiyomi.presentation.core.screens.LoadingScreen import tachiyomi.source.local.entries.anime.LocalAnimeSource data class AnimeSourceSearchScreen( @@ -44,6 +46,11 @@ data class AnimeSourceSearchScreen( @Composable override fun Content() { + if (!ifAnimeSourcesLoaded()) { + LoadingScreen() + return + } + val uriHandler = LocalUriHandler.current val navigator = LocalNavigator.currentOrThrow val scope = rememberCoroutineScope() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/source/browse/BrowseAnimeSourceScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/source/browse/BrowseAnimeSourceScreen.kt index f6ebb7f8d..b76d226d4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/source/browse/BrowseAnimeSourceScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/source/browse/BrowseAnimeSourceScreen.kt @@ -35,6 +35,7 @@ import androidx.paging.compose.collectAsLazyPagingItems import cafe.adriel.voyager.core.model.rememberScreenModel import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.core.util.ifAnimeSourcesLoaded import eu.kanade.presentation.browse.anime.BrowseAnimeSourceContent import eu.kanade.presentation.browse.anime.MissingSourceScreen import eu.kanade.presentation.browse.anime.components.BrowseAnimeSourceToolbar @@ -60,6 +61,7 @@ import tachiyomi.i18n.MR import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.components.material.padding import tachiyomi.presentation.core.i18n.stringResource +import tachiyomi.presentation.core.screens.LoadingScreen import tachiyomi.source.local.entries.anime.LocalAnimeSource data class BrowseAnimeSourceScreen( @@ -73,6 +75,11 @@ data class BrowseAnimeSourceScreen( @Composable override fun Content() { + if (!ifAnimeSourcesLoaded()) { + LoadingScreen() + return + } + val screenModel = rememberScreenModel { BrowseAnimeSourceScreenModel(sourceId, listingQuery) } val state by screenModel.state.collectAsState() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/source/globalsearch/GlobalAnimeSearchScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/source/globalsearch/GlobalAnimeSearchScreen.kt index 76055fbc1..efb1e8c19 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/source/globalsearch/GlobalAnimeSearchScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/anime/source/globalsearch/GlobalAnimeSearchScreen.kt @@ -10,6 +10,7 @@ import androidx.compose.runtime.setValue import cafe.adriel.voyager.core.model.rememberScreenModel import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.core.util.ifAnimeSourcesLoaded import eu.kanade.presentation.browse.anime.GlobalAnimeSearchScreen import eu.kanade.presentation.util.Screen import eu.kanade.tachiyomi.ui.browse.anime.source.browse.BrowseAnimeSourceScreen @@ -23,6 +24,11 @@ class GlobalAnimeSearchScreen( @Composable override fun Content() { + if (!ifAnimeSourcesLoaded()) { + LoadingScreen() + return + } + val navigator = LocalNavigator.currentOrThrow val screenModel = rememberScreenModel { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/extension/details/MangaSourcePreferencesScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/extension/details/MangaSourcePreferencesScreen.kt index d2573b61b..554c61e9a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/extension/details/MangaSourcePreferencesScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/extension/details/MangaSourcePreferencesScreen.kt @@ -31,6 +31,7 @@ import androidx.preference.forEach import androidx.preference.getOnBindEditTextListener import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.core.util.ifMangaSourcesLoaded import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.util.Screen import eu.kanade.tachiyomi.R @@ -40,6 +41,7 @@ import eu.kanade.tachiyomi.source.sourcePreferences import eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText.Companion.setIncognito import tachiyomi.domain.source.manga.service.MangaSourceManager import tachiyomi.presentation.core.components.material.Scaffold +import tachiyomi.presentation.core.screens.LoadingScreen import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -47,6 +49,11 @@ class MangaSourcePreferencesScreen(val sourceId: Long) : Screen() { @Composable override fun Content() { + if (!ifMangaSourcesLoaded()) { + LoadingScreen() + return + } + val context = LocalContext.current val navigator = LocalNavigator.currentOrThrow diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/migration/search/MangaSourceSearchScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/migration/search/MangaSourceSearchScreen.kt index 8fdd5253f..06efc8adc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/migration/search/MangaSourceSearchScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/migration/search/MangaSourceSearchScreen.kt @@ -18,6 +18,7 @@ import androidx.paging.compose.collectAsLazyPagingItems import cafe.adriel.voyager.core.model.rememberScreenModel import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.core.util.ifMangaSourcesLoaded import eu.kanade.presentation.browse.manga.BrowseSourceContent import eu.kanade.presentation.components.SearchToolbar import eu.kanade.presentation.util.Screen @@ -34,6 +35,7 @@ import tachiyomi.i18n.MR import tachiyomi.presentation.core.components.material.ExtendedFloatingActionButton import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.i18n.stringResource +import tachiyomi.presentation.core.screens.LoadingScreen import tachiyomi.source.local.entries.manga.LocalMangaSource data class MangaSourceSearchScreen( @@ -44,6 +46,11 @@ data class MangaSourceSearchScreen( @Composable override fun Content() { + if (!ifMangaSourcesLoaded()) { + LoadingScreen() + return + } + val uriHandler = LocalUriHandler.current val navigator = LocalNavigator.currentOrThrow val scope = rememberCoroutineScope() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/source/browse/BrowseMangaSourceScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/source/browse/BrowseMangaSourceScreen.kt index 94c7f5f7f..61540f195 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/source/browse/BrowseMangaSourceScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/source/browse/BrowseMangaSourceScreen.kt @@ -35,6 +35,7 @@ import androidx.paging.compose.collectAsLazyPagingItems import cafe.adriel.voyager.core.model.rememberScreenModel import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.core.util.ifMangaSourcesLoaded import eu.kanade.presentation.browse.anime.components.RemoveEntryDialog import eu.kanade.presentation.browse.manga.BrowseSourceContent import eu.kanade.presentation.browse.manga.MissingSourceScreen @@ -60,6 +61,7 @@ import tachiyomi.i18n.MR import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.components.material.padding import tachiyomi.presentation.core.i18n.stringResource +import tachiyomi.presentation.core.screens.LoadingScreen import tachiyomi.source.local.entries.manga.LocalMangaSource data class BrowseMangaSourceScreen( @@ -73,6 +75,11 @@ data class BrowseMangaSourceScreen( @Composable override fun Content() { + if (!ifMangaSourcesLoaded()) { + LoadingScreen() + return + } + val screenModel = rememberScreenModel { BrowseMangaSourceScreenModel(sourceId, listingQuery) } val state by screenModel.state.collectAsState() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/source/globalsearch/GlobalMangaSearchScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/source/globalsearch/GlobalMangaSearchScreen.kt index c3ee40a65..b6168ba31 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/source/globalsearch/GlobalMangaSearchScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/manga/source/globalsearch/GlobalMangaSearchScreen.kt @@ -10,6 +10,7 @@ import androidx.compose.runtime.setValue import cafe.adriel.voyager.core.model.rememberScreenModel import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.core.util.ifMangaSourcesLoaded import eu.kanade.presentation.browse.manga.GlobalMangaSearchScreen import eu.kanade.presentation.util.Screen import eu.kanade.tachiyomi.ui.browse.manga.source.browse.BrowseMangaSourceScreen @@ -23,6 +24,11 @@ class GlobalMangaSearchScreen( @Composable override fun Content() { + if (!ifMangaSourcesLoaded()) { + LoadingScreen() + return + } + val navigator = LocalNavigator.currentOrThrow val screenModel = rememberScreenModel { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/entries/anime/AnimeScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/entries/anime/AnimeScreen.kt index f2067a38f..d61b756c0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/entries/anime/AnimeScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/entries/anime/AnimeScreen.kt @@ -20,6 +20,7 @@ import cafe.adriel.voyager.core.model.rememberScreenModel import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.Navigator import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.core.util.ifAnimeSourcesLoaded import eu.kanade.domain.entries.anime.model.hasCustomCover import eu.kanade.domain.entries.anime.model.toSAnime import eu.kanade.presentation.category.components.ChangeCategoryDialog @@ -76,6 +77,11 @@ class AnimeScreen( @Composable override fun Content() { + if (!ifAnimeSourcesLoaded()) { + LoadingScreen() + return + } + val navigator = LocalNavigator.currentOrThrow val context = LocalContext.current val haptic = LocalHapticFeedback.current diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/entries/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/entries/manga/MangaScreen.kt index 09e492504..34d83e646 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/entries/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/entries/manga/MangaScreen.kt @@ -22,6 +22,7 @@ import cafe.adriel.voyager.core.model.rememberScreenModel import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.Navigator import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.core.util.ifMangaSourcesLoaded import eu.kanade.domain.entries.manga.model.hasCustomCover import eu.kanade.domain.entries.manga.model.toSManga import eu.kanade.presentation.category.components.ChangeCategoryDialog @@ -74,6 +75,11 @@ class MangaScreen( @Composable override fun Content() { + if (!ifMangaSourcesLoaded()) { + LoadingScreen() + return + } + val navigator = LocalNavigator.currentOrThrow val context = LocalContext.current val haptic = LocalHapticFeedback.current diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerViewModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerViewModel.kt index a2fc096ae..2a4f0f60a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerViewModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerViewModel.kt @@ -44,6 +44,7 @@ import `is`.xyz.mpv.Utils import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.runBlocking @@ -245,6 +246,7 @@ class PlayerViewModel @JvmOverloads constructor( return try { val anime = getAnime.await(animeId) if (anime != null) { + sourceManager.isInitialized.first { it } if (episodeId == -1L) episodeId = initialEpisodeId checkTrackers(anime) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index f709692df..cb35d8592 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -40,6 +40,7 @@ import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.google.android.material.elevation.SurfaceColors import com.google.android.material.transition.platform.MaterialContainerTransform import dev.chrisbanes.insetter.applyInsetter +import eu.kanade.core.util.ifMangaSourcesLoaded import eu.kanade.domain.base.BasePreferences import eu.kanade.presentation.reader.DisplayRefreshHost import eu.kanade.presentation.reader.OrientationSelectDialog @@ -350,6 +351,10 @@ class ReaderActivity : BaseActivity() { ) } + if (!ifMangaSourcesLoaded()) { + return@setComposeContent + } + val isHttpSource = viewModel.getSource() is HttpSource val isFullscreen by readerPreferences.fullscreen().collectAsState() val flashOnPageChange by readerPreferences.flashOnPageChange().collectAsState() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt index 5f9d2e1e1..2d9e05443 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt @@ -47,6 +47,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filterNotNull +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach @@ -270,6 +271,7 @@ class ReaderViewModel @JvmOverloads constructor( try { val manga = getManga.await(mangaId) if (manga != null) { + sourceManager.isInitialized.first { it } mutableState.update { it.copy(manga = manga) } if (chapterId == -1L) chapterId = initialChapterId diff --git a/domain/src/main/java/tachiyomi/domain/source/anime/service/AnimeSourceManager.kt b/domain/src/main/java/tachiyomi/domain/source/anime/service/AnimeSourceManager.kt index 5d64d35c4..b6d5b3dd9 100644 --- a/domain/src/main/java/tachiyomi/domain/source/anime/service/AnimeSourceManager.kt +++ b/domain/src/main/java/tachiyomi/domain/source/anime/service/AnimeSourceManager.kt @@ -4,10 +4,13 @@ import eu.kanade.tachiyomi.animesource.AnimeCatalogueSource import eu.kanade.tachiyomi.animesource.AnimeSource import eu.kanade.tachiyomi.animesource.online.AnimeHttpSource import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.StateFlow import tachiyomi.domain.source.anime.model.StubAnimeSource interface AnimeSourceManager { + val isInitialized: StateFlow + val catalogueSources: Flow> fun get(sourceKey: Long): AnimeSource? diff --git a/domain/src/main/java/tachiyomi/domain/source/manga/service/MangaSourceManager.kt b/domain/src/main/java/tachiyomi/domain/source/manga/service/MangaSourceManager.kt index 613746b26..30dbf17c0 100644 --- a/domain/src/main/java/tachiyomi/domain/source/manga/service/MangaSourceManager.kt +++ b/domain/src/main/java/tachiyomi/domain/source/manga/service/MangaSourceManager.kt @@ -4,10 +4,13 @@ import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.MangaSource import eu.kanade.tachiyomi.source.online.HttpSource import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.StateFlow import tachiyomi.domain.source.manga.model.StubMangaSource interface MangaSourceManager { + val isInitialized: StateFlow + val catalogueSources: Flow> fun get(sourceKey: Long): MangaSource?