diff --git a/app/src/main/java/io/legado/app/data/entities/BaseSource.kt b/app/src/main/java/io/legado/app/data/entities/BaseSource.kt index 82be3ca2b..a7229cd19 100644 --- a/app/src/main/java/io/legado/app/data/entities/BaseSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BaseSource.kt @@ -9,8 +9,8 @@ import io.legado.app.constant.AppLog import io.legado.app.data.entities.rule.RowUi import io.legado.app.help.CacheManager import io.legado.app.help.JsExtensions -import io.legado.app.help.crypto.SymmetricCryptoAndroid import io.legado.app.help.config.AppConfig +import io.legado.app.help.crypto.SymmetricCryptoAndroid import io.legado.app.help.http.CookieStore import io.legado.app.help.source.getShareScope import io.legado.app.utils.GSON @@ -242,9 +242,13 @@ interface BaseSource : JsExtensions { bindings["cookie"] = CookieStore bindings["cache"] = CacheManager } - val scope = RhinoScriptEngine.getRuntimeScope(bindings) - getShareScope()?.let { - scope.prototype = it + val sharedScope = getShareScope() + val scope = if (sharedScope == null) { + RhinoScriptEngine.getRuntimeScope(bindings) + } else { + bindings.apply { + prototype = sharedScope + } } return RhinoScriptEngine.eval(jsStr, scope) } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index d9997d813..bba4a8e5f 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -351,9 +351,13 @@ class AnalyzeUrl( bindings["source"] = source bindings["result"] = result } - val scope = RhinoScriptEngine.getRuntimeScope(bindings) - source?.getShareScope(coroutineContext)?.let { - scope.prototype = it + val sharedScope = source?.getShareScope(coroutineContext) + val scope = if (sharedScope == null) { + RhinoScriptEngine.getRuntimeScope(bindings) + } else { + bindings.apply { + prototype = sharedScope + } } return RhinoScriptEngine.eval(jsStr, scope, coroutineContext) } diff --git a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt index 4f1b02709..f90d5fab0 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt @@ -89,6 +89,7 @@ object BookInfo { Debug.log(bookSource.bookSourceUrl, "└${it}") } ?: Debug.log(bookSource.bookSourceUrl, "└") } catch (e: Exception) { + coroutineContext.ensureActive() Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") DebugLog.e("获取分类出错", e) } @@ -100,6 +101,7 @@ object BookInfo { Debug.log(bookSource.bookSourceUrl, "└${it}") } } catch (e: Exception) { + coroutineContext.ensureActive() Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") DebugLog.e("获取字数出错", e) } @@ -111,6 +113,7 @@ object BookInfo { Debug.log(bookSource.bookSourceUrl, "└${it}") } } catch (e: Exception) { + coroutineContext.ensureActive() Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") DebugLog.e("获取最新章节出错", e) } @@ -122,6 +125,7 @@ object BookInfo { Debug.log(bookSource.bookSourceUrl, "└${it}") } } catch (e: Exception) { + coroutineContext.ensureActive() Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") DebugLog.e("获取简介出错", e) } @@ -136,11 +140,12 @@ object BookInfo { Debug.log(bookSource.bookSourceUrl, "└${it}") } } catch (e: Exception) { + coroutineContext.ensureActive() Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") DebugLog.e("获取封面出错", e) } + coroutineContext.ensureActive() if (!book.isWebFile) { - coroutineContext.ensureActive() Debug.log(bookSource.bookSourceUrl, "┌获取目录链接") book.tocUrl = analyzeRule.getString(infoRule.tocUrl, isUrl = true) if (book.tocUrl.isEmpty()) book.tocUrl = baseUrl @@ -149,7 +154,6 @@ object BookInfo { } Debug.log(bookSource.bookSourceUrl, "└${book.tocUrl}") } else { - coroutineContext.ensureActive() Debug.log(bookSource.bookSourceUrl, "┌获取文件下载链接") book.downloadUrls = analyzeRule.getStringList(infoRule.downloadUrls, isUrl = true) if (book.downloadUrls.isNullOrEmpty()) { diff --git a/app/src/main/java/io/legado/app/model/webBook/BookList.kt b/app/src/main/java/io/legado/app/model/webBook/BookList.kt index f85496351..9f33dd666 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookList.kt @@ -224,6 +224,7 @@ object BookList { searchBook.kind = analyzeRule.getStringList(ruleKind)?.joinToString(",") Debug.log(bookSource.bookSourceUrl, "└${searchBook.kind ?: ""}", log) } catch (e: Exception) { + coroutineContext.ensureActive() Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log) } coroutineContext.ensureActive() @@ -231,7 +232,8 @@ object BookList { try { searchBook.wordCount = wordCountFormat(analyzeRule.getString(ruleWordCount)) Debug.log(bookSource.bookSourceUrl, "└${searchBook.wordCount}", log) - } catch (e: java.lang.Exception) { + } catch (e: Exception) { + coroutineContext.ensureActive() Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log) } coroutineContext.ensureActive() @@ -239,7 +241,8 @@ object BookList { try { searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter) Debug.log(bookSource.bookSourceUrl, "└${searchBook.latestChapterTitle}", log) - } catch (e: java.lang.Exception) { + } catch (e: Exception) { + coroutineContext.ensureActive() Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log) } coroutineContext.ensureActive() @@ -247,7 +250,8 @@ object BookList { try { searchBook.intro = HtmlFormatter.format(analyzeRule.getString(ruleIntro)) Debug.log(bookSource.bookSourceUrl, "└${searchBook.intro}", log) - } catch (e: java.lang.Exception) { + } catch (e: Exception) { + coroutineContext.ensureActive() Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log) } coroutineContext.ensureActive() @@ -259,7 +263,8 @@ object BookList { } } Debug.log(bookSource.bookSourceUrl, "└${searchBook.coverUrl ?: ""}", log) - } catch (e: java.lang.Exception) { + } catch (e: Exception) { + coroutineContext.ensureActive() Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log) } coroutineContext.ensureActive() diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt index 1033fd1be..0a0b1c289 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt @@ -199,6 +199,7 @@ class BookSourceDebugActivity : VMBaseActivity showHelp("debugHelp") } return super.onCompatOptionsItemSelected(item)