From 68eddefb94afcbead3a08e1754ad4f87e46c52c4 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Wed, 27 Mar 2024 23:26:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/book/BookHelp.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/book/BookHelp.kt b/app/src/main/java/io/legado/app/help/book/BookHelp.kt index 10b034cc4..40f47f3a0 100644 --- a/app/src/main/java/io/legado/app/help/book/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/book/BookHelp.kt @@ -30,6 +30,7 @@ import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay +import kotlinx.coroutines.ensureActive import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.flow import kotlinx.coroutines.withContext @@ -43,6 +44,7 @@ import java.io.IOException import java.util.concurrent.ConcurrentHashMap import java.util.regex.Pattern import java.util.zip.ZipFile +import kotlin.coroutines.coroutineContext import kotlin.math.abs import kotlin.math.max import kotlin.math.min @@ -200,10 +202,9 @@ object BookHelp { ).writeBytes(it) } } catch (e: Exception) { - AppLog.put( - "${book.name} ${chapter?.title} 图片 $src 下载失败\n${e.localizedMessage}", - e - ) + coroutineContext.ensureActive() + val msg = "${book.name} ${chapter?.title} 图片 $src 下载失败\n${e.localizedMessage}" + AppLog.put(msg, e) } finally { downloadImages.remove(src) }