From 09531e7f5a33508afb4a53542ce7b0f601be8826 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sun, 17 Dec 2023 21:55:54 +0700 Subject: [PATCH] MangaScreenModel: Start downloads in IO dispatcher (#10241) --- .../tachiyomi/ui/manga/MangaScreenModel.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index 30f4421b9e..a6541fe30d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -636,18 +636,18 @@ class MangaScreenModel( ) { val successState = successState ?: return - if (startNow) { - val chapterId = chapters.singleOrNull()?.id ?: return - downloadManager.startDownloadNow(chapterId) - } else { - downloadChapters(chapters) - } - - if (!isFavorited && !successState.hasPromptedToAddBefore) { - updateSuccessState { state -> - state.copy(hasPromptedToAddBefore = true) + screenModelScope.launchNonCancellable { + if (startNow) { + val chapterId = chapters.singleOrNull()?.id ?: return@launchNonCancellable + downloadManager.startDownloadNow(chapterId) + } else { + downloadChapters(chapters) } - screenModelScope.launch { + + if (!isFavorited && !successState.hasPromptedToAddBefore) { + updateSuccessState { state -> + state.copy(hasPromptedToAddBefore = true) + } val result = snackbarHostState.showSnackbar( message = context.stringResource(MR.strings.snack_add_to_library), actionLabel = context.stringResource(MR.strings.action_add),