From 088576cc9dd3c4d6ceba38117ceaeef9b80f85db Mon Sep 17 00:00:00 2001 From: Koitharu Date: Mon, 7 Jul 2025 13:46:37 +0300 Subject: [PATCH] Ignore network error for background progress update --- .../org/koitharu/kotatsu/core/ui/BaseViewModel.kt | 10 ++++++++-- .../koitharu/kotatsu/details/ui/DetailsViewModel.kt | 2 +- gradle/libs.versions.toml | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/BaseViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/BaseViewModel.kt index d98e67739..84b73c99e 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/BaseViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/BaseViewModel.kt @@ -22,6 +22,7 @@ import org.koitharu.kotatsu.core.util.ext.EventFlow import org.koitharu.kotatsu.core.util.ext.MutableEventFlow import org.koitharu.kotatsu.core.util.ext.call import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug +import kotlin.coroutines.AbstractCoroutineContextElement import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext @@ -80,10 +81,15 @@ abstract class BaseViewModel : ViewModel() { protected fun MutableStateFlow.decrement() = update { it - 1 } - private fun createErrorHandler() = CoroutineExceptionHandler { _, throwable -> + private fun createErrorHandler() = CoroutineExceptionHandler { coroutineContext, throwable -> throwable.printStackTraceDebug() - if (throwable !is CancellationException) { + if (coroutineContext[SkipErrors.key] == null && throwable !is CancellationException) { errorEvent.call(throwable) } } + + protected object SkipErrors : AbstractCoroutineContextElement(Key) { + + private object Key : CoroutineContext.Key + } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt index 03108896b..57d2028d7 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt @@ -182,7 +182,7 @@ class DetailsViewModel @Inject constructor( init { loadingJob = doLoad(force = false) - launchJob(Dispatchers.Default) { + launchJob(Dispatchers.Default + SkipErrors) { val manga = mangaDetails.firstOrNull { !it?.chapters.isNullOrEmpty() } ?: return@launchJob val h = history.firstOrNull() if (h != null) { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 796d6c2a3..bc2c4a66f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,6 +13,7 @@ constraintlayout = "2.2.1" coreKtx = "1.16.0" coroutines = "1.10.2" dagger = "2.56.2" +decoroutinator = "2.5.4" desugar = "2.1.5" diskLruCache = "1.5" documentfile = "1.1.0" @@ -119,3 +120,4 @@ kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlinx-serizliation = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } room = { id = "androidx.room", version.ref = "room" } +decoroutinator = { id = "dev.reformator.stacktracedecoroutinator", version.ref = "decoroutinator" }