From 03af785add68270def405e6c06cbf4893e493f90 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Mon, 18 Dec 2023 18:21:52 +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 --- .../java/io/legado/app/service/CacheBookService.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/CacheBookService.kt b/app/src/main/java/io/legado/app/service/CacheBookService.kt index a4bd9a73e..e646d0683 100644 --- a/app/src/main/java/io/legado/app/service/CacheBookService.kt +++ b/app/src/main/java/io/legado/app/service/CacheBookService.kt @@ -18,7 +18,6 @@ import io.legado.app.ui.book.cache.CacheActivity import io.legado.app.utils.activityPendingIntent import io.legado.app.utils.postEvent import io.legado.app.utils.servicePendingIntent -import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Job import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.delay @@ -106,10 +105,19 @@ class CacheBookService : BaseService() { val chapterCount = appDb.bookChapterDao.getChapterCount(bookUrl) if (chapterCount == 0) { val name = cacheBook.book.name + if (cacheBook.book.tocUrl.isEmpty()) { + kotlin.runCatching { + WebBook.getBookInfoAwait(cacheBook.bookSource, cacheBook.book) + }.onFailure { + val msg = "《$name》目录为空且加载详情页失败\n${it.localizedMessage}" + AppLog.put(msg, it, true) + return@execute + } + } WebBook.getChapterListAwait(cacheBook.bookSource, cacheBook.book).onFailure { cacheBook.book.totalChapterNum = 0 - AppLog.put("《$name》目录为空且加载目录失败\n${it.localizedMessage}", it) - appCtx.toastOnUi("《$name》目录为空且加载目录失败\n${it.localizedMessage}") + AppLog.put("《$name》目录为空且加载目录失败\n${it.localizedMessage}", it, true) + return@execute }.getOrNull()?.let { toc -> appDb.bookChapterDao.insert(*toc.toTypedArray()) }