This commit is contained in:
Horis
2025-05-10 11:05:00 +08:00
parent f05650a35a
commit 0e2124824f
5 changed files with 20 additions and 3 deletions
@@ -16,6 +16,7 @@ import io.legado.app.utils.findNSPrefix
import io.legado.app.utils.printOnDebug import io.legado.app.utils.printOnDebug
import io.legado.app.utils.toRequestBody import io.legado.app.utils.toRequestBody
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType import okhttp3.MediaType.Companion.toMediaType
@@ -35,6 +36,7 @@ import java.time.LocalDateTime
import java.time.ZoneOffset import java.time.ZoneOffset
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.coroutines.coroutineContext
@Suppress("unused", "MemberVisibilityCanBePrivate") @Suppress("unused", "MemberVisibilityCanBePrivate")
open class WebDav( open class WebDav(
@@ -245,6 +247,8 @@ open class WebDav(
val requestBody = EXISTS.toRequestBody("application/xml".toMediaType()) val requestBody = EXISTS.toRequestBody("application/xml".toMediaType())
method("PROPFIND", requestBody) method("PROPFIND", requestBody)
}.use { it.isSuccessful } }.use { it.isSuccessful }
}.onFailure {
coroutineContext.ensureActive()
}.getOrDefault(false) }.getOrDefault(false)
} }
@@ -259,6 +263,8 @@ open class WebDav(
val requestBody = EXISTS.toRequestBody("application/xml".toMediaType()) val requestBody = EXISTS.toRequestBody("application/xml".toMediaType())
method("PROPFIND", requestBody) method("PROPFIND", requestBody)
}.use { it.code != 401 } }.use { it.code != 401 }
}.onFailure {
coroutineContext.ensureActive()
}.getOrDefault(true) }.getOrDefault(true)
} }
@@ -279,6 +285,7 @@ open class WebDav(
} }
} }
}.onFailure { }.onFailure {
coroutineContext.ensureActive()
AppLog.put("WebDav创建目录失败\n${it.localizedMessage}", it) AppLog.put("WebDav创建目录失败\n${it.localizedMessage}", it)
}.isSuccess }.isSuccess
} }
@@ -335,6 +342,7 @@ open class WebDav(
} }
} }
}.onFailure { }.onFailure {
coroutineContext.ensureActive()
AppLog.put("WebDav上传失败\n${it.localizedMessage}", it) AppLog.put("WebDav上传失败\n${it.localizedMessage}", it)
throw WebDavException("WebDav上传失败\n${it.localizedMessage}") throw WebDavException("WebDav上传失败\n${it.localizedMessage}")
} }
@@ -355,6 +363,7 @@ open class WebDav(
} }
} }
}.onFailure { }.onFailure {
coroutineContext.ensureActive()
AppLog.put("WebDav上传失败\n${it.localizedMessage}", it) AppLog.put("WebDav上传失败\n${it.localizedMessage}", it)
throw WebDavException("WebDav上传失败\n${it.localizedMessage}") throw WebDavException("WebDav上传失败\n${it.localizedMessage}")
} }
@@ -375,6 +384,7 @@ open class WebDav(
} }
} }
}.onFailure { }.onFailure {
coroutineContext.ensureActive()
AppLog.put("WebDav上传失败\n${it.localizedMessage}", it) AppLog.put("WebDav上传失败\n${it.localizedMessage}", it)
throw WebDavException("WebDav上传失败\n${it.localizedMessage}") throw WebDavException("WebDav上传失败\n${it.localizedMessage}")
} }
@@ -405,6 +415,7 @@ open class WebDav(
checkResult(it) checkResult(it)
} }
}.onFailure { }.onFailure {
coroutineContext.ensureActive()
AppLog.put("WebDav删除失败\n${it.localizedMessage}", it) AppLog.put("WebDav删除失败\n${it.localizedMessage}", it)
}.isSuccess }.isSuccess
} }
@@ -200,6 +200,7 @@ object ReadBook : CoroutineScope by MainScope() {
) { ) {
durChapterIndex = progress.durChapterIndex durChapterIndex = progress.durChapterIndex
durChapterPos = progress.durChapterPos durChapterPos = progress.durChapterPos
saveRead()
clearTextChapter() clearTextChapter()
callBack?.upContent() callBack?.upContent()
loadContent(resetPageOffset = true) loadContent(resetPageOffset = true)
@@ -217,6 +217,7 @@ object WebBook {
.evalJS(preUpdateJs) .evalJS(preUpdateJs)
} }
}.onFailure { }.onFailure {
coroutineContext.ensureActive()
AppLog.put("执行preUpdateJs规则失败 书源:${bookSource.bookSourceName}", it) AppLog.put("执行preUpdateJs规则失败 书源:${bookSource.bookSourceName}", it)
} }
} }
@@ -264,6 +265,8 @@ object WebBook {
body = res.body body = res.body
) )
} }
}.onFailure {
coroutineContext.ensureActive()
} }
} }
@@ -391,6 +394,8 @@ object WebBook {
return@runCatching searchBook.toBook() return@runCatching searchBook.toBook()
} }
throw NoStackTraceException("未搜索到 $name($author) 书籍") throw NoStackTraceException("未搜索到 $name($author) 书籍")
}.onFailure {
coroutineContext.ensureActive()
} }
} }
@@ -22,6 +22,7 @@ import io.legado.app.utils.stackTraceStr
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import io.legado.app.utils.writeToOutputStream import io.legado.app.utils.writeToOutputStream
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
import java.io.File import java.io.File
@@ -92,8 +93,8 @@ class BookshelfManageViewModel(application: Application) : BaseViewModel(applica
AppLog.put("搜索书籍出错\n${it.localizedMessage}", it, true) AppLog.put("搜索书籍出错\n${it.localizedMessage}", it, true)
}.getOrNull() ?: return@forEachIndexed }.getOrNull() ?: return@forEachIndexed
kotlin.runCatching { kotlin.runCatching {
if (book.tocUrl.isEmpty()) { if (newBook.tocUrl.isEmpty()) {
WebBook.getBookInfoAwait(source, book) WebBook.getBookInfoAwait(source, newBook)
} }
}.onFailure { }.onFailure {
AppLog.put("获取书籍详情出错\n${it.localizedMessage}", it, true) AppLog.put("获取书籍详情出错\n${it.localizedMessage}", it, true)
@@ -1557,7 +1557,6 @@ class ReadBookActivity : BaseReadBookActivity(),
setMessage(R.string.cloud_progress_exceeds_current) setMessage(R.string.cloud_progress_exceeds_current)
okButton { okButton {
ReadBook.setProgress(progress) ReadBook.setProgress(progress)
ReadBook.saveRead()
} }
noButton() noButton()
} }