Horis 1 год назад
Родитель
Сommit
ecbd1eb41b

+ 8 - 4
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)
     }

+ 7 - 3
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)
     }

+ 6 - 2
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()) {

+ 9 - 4
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()

+ 1 - 0
app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt

@@ -199,6 +199,7 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
                 openOrCloseHelp(true)
                 initExploreKinds()
             }
+
             R.id.menu_help -> showHelp("debugHelp")
         }
         return super.onCompatOptionsItemSelected(item)