Horis 2 年之前
父节点
当前提交
41ca353d50
共有 1 个文件被更改,包括 11 次插入 和 3 次删除
  1. 11 3
      app/src/main/java/io/legado/app/service/CacheBookService.kt

+ 11 - 3
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.activityPendingIntent
 import io.legado.app.utils.postEvent
 import io.legado.app.utils.postEvent
 import io.legado.app.utils.servicePendingIntent
 import io.legado.app.utils.servicePendingIntent
-import io.legado.app.utils.toastOnUi
 import kotlinx.coroutines.Job
 import kotlinx.coroutines.Job
 import kotlinx.coroutines.asCoroutineDispatcher
 import kotlinx.coroutines.asCoroutineDispatcher
 import kotlinx.coroutines.delay
 import kotlinx.coroutines.delay
@@ -106,10 +105,19 @@ class CacheBookService : BaseService() {
             val chapterCount = appDb.bookChapterDao.getChapterCount(bookUrl)
             val chapterCount = appDb.bookChapterDao.getChapterCount(bookUrl)
             if (chapterCount == 0) {
             if (chapterCount == 0) {
                 val name = cacheBook.book.name
                 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 {
                 WebBook.getChapterListAwait(cacheBook.bookSource, cacheBook.book).onFailure {
                     cacheBook.book.totalChapterNum = 0
                     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 ->
                 }.getOrNull()?.let { toc ->
                     appDb.bookChapterDao.insert(*toc.toTypedArray())
                     appDb.bookChapterDao.insert(*toc.toTypedArray())
                 }
                 }