This commit is contained in:
Horis
2025-05-07 18:27:24 +08:00
parent 65e5859524
commit d457f40d4a

View File

@@ -39,6 +39,7 @@ import io.legado.app.utils.mapParallelSafe
import io.legado.app.utils.postEvent
import io.legado.app.utils.toStringArray
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
@@ -51,6 +52,7 @@ import java.io.File
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.io.FileOutputStream
import kotlin.coroutines.coroutineContext
/**
* 阅读界面数据处理
@@ -164,6 +166,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
WebBook.getBookInfoAwait(source, book, canReName = false)
return true
} catch (e: Throwable) {
coroutineContext.ensureActive()
ReadBook.upMsg("详情页出错: ${e.localizedMessage}")
return false
}
@@ -219,6 +222,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.onChapterListUpdated(book)
return true
}.onFailure {
coroutineContext.ensureActive()
ReadBook.upMsg(context.getString(R.string.error_load_toc))
return false
}