This commit is contained in:
Horis
2025-04-22 12:00:07 +08:00
parent 748ad34fe1
commit 645a0b274a
5 changed files with 31 additions and 13 deletions
@@ -9,8 +9,8 @@ import io.legado.app.constant.AppLog
import io.legado.app.data.entities.rule.RowUi import io.legado.app.data.entities.rule.RowUi
import io.legado.app.help.CacheManager import io.legado.app.help.CacheManager
import io.legado.app.help.JsExtensions 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.config.AppConfig
import io.legado.app.help.crypto.SymmetricCryptoAndroid
import io.legado.app.help.http.CookieStore import io.legado.app.help.http.CookieStore
import io.legado.app.help.source.getShareScope import io.legado.app.help.source.getShareScope
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
@@ -242,9 +242,13 @@ interface BaseSource : JsExtensions {
bindings["cookie"] = CookieStore bindings["cookie"] = CookieStore
bindings["cache"] = CacheManager bindings["cache"] = CacheManager
} }
val scope = RhinoScriptEngine.getRuntimeScope(bindings) val sharedScope = getShareScope()
getShareScope()?.let { val scope = if (sharedScope == null) {
scope.prototype = it RhinoScriptEngine.getRuntimeScope(bindings)
} else {
bindings.apply {
prototype = sharedScope
}
} }
return RhinoScriptEngine.eval(jsStr, scope) return RhinoScriptEngine.eval(jsStr, scope)
} }
@@ -351,9 +351,13 @@ class AnalyzeUrl(
bindings["source"] = source bindings["source"] = source
bindings["result"] = result bindings["result"] = result
} }
val scope = RhinoScriptEngine.getRuntimeScope(bindings) val sharedScope = source?.getShareScope(coroutineContext)
source?.getShareScope(coroutineContext)?.let { val scope = if (sharedScope == null) {
scope.prototype = it RhinoScriptEngine.getRuntimeScope(bindings)
} else {
bindings.apply {
prototype = sharedScope
}
} }
return RhinoScriptEngine.eval(jsStr, scope, coroutineContext) return RhinoScriptEngine.eval(jsStr, scope, coroutineContext)
} }
@@ -89,6 +89,7 @@ object BookInfo {
Debug.log(bookSource.bookSourceUrl, "└${it}") Debug.log(bookSource.bookSourceUrl, "└${it}")
} ?: Debug.log(bookSource.bookSourceUrl, "└") } ?: Debug.log(bookSource.bookSourceUrl, "└")
} catch (e: Exception) { } catch (e: Exception) {
coroutineContext.ensureActive()
Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}")
DebugLog.e("获取分类出错", e) DebugLog.e("获取分类出错", e)
} }
@@ -100,6 +101,7 @@ object BookInfo {
Debug.log(bookSource.bookSourceUrl, "└${it}") Debug.log(bookSource.bookSourceUrl, "└${it}")
} }
} catch (e: Exception) { } catch (e: Exception) {
coroutineContext.ensureActive()
Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}")
DebugLog.e("获取字数出错", e) DebugLog.e("获取字数出错", e)
} }
@@ -111,6 +113,7 @@ object BookInfo {
Debug.log(bookSource.bookSourceUrl, "└${it}") Debug.log(bookSource.bookSourceUrl, "└${it}")
} }
} catch (e: Exception) { } catch (e: Exception) {
coroutineContext.ensureActive()
Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}")
DebugLog.e("获取最新章节出错", e) DebugLog.e("获取最新章节出错", e)
} }
@@ -122,6 +125,7 @@ object BookInfo {
Debug.log(bookSource.bookSourceUrl, "└${it}") Debug.log(bookSource.bookSourceUrl, "└${it}")
} }
} catch (e: Exception) { } catch (e: Exception) {
coroutineContext.ensureActive()
Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}")
DebugLog.e("获取简介出错", e) DebugLog.e("获取简介出错", e)
} }
@@ -136,11 +140,12 @@ object BookInfo {
Debug.log(bookSource.bookSourceUrl, "└${it}") Debug.log(bookSource.bookSourceUrl, "└${it}")
} }
} catch (e: Exception) { } catch (e: Exception) {
coroutineContext.ensureActive()
Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}")
DebugLog.e("获取封面出错", e) DebugLog.e("获取封面出错", e)
} }
coroutineContext.ensureActive()
if (!book.isWebFile) { if (!book.isWebFile) {
coroutineContext.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取目录链接") Debug.log(bookSource.bookSourceUrl, "┌获取目录链接")
book.tocUrl = analyzeRule.getString(infoRule.tocUrl, isUrl = true) book.tocUrl = analyzeRule.getString(infoRule.tocUrl, isUrl = true)
if (book.tocUrl.isEmpty()) book.tocUrl = baseUrl if (book.tocUrl.isEmpty()) book.tocUrl = baseUrl
@@ -149,7 +154,6 @@ object BookInfo {
} }
Debug.log(bookSource.bookSourceUrl, "└${book.tocUrl}") Debug.log(bookSource.bookSourceUrl, "└${book.tocUrl}")
} else { } else {
coroutineContext.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取文件下载链接") Debug.log(bookSource.bookSourceUrl, "┌获取文件下载链接")
book.downloadUrls = analyzeRule.getStringList(infoRule.downloadUrls, isUrl = true) book.downloadUrls = analyzeRule.getStringList(infoRule.downloadUrls, isUrl = true)
if (book.downloadUrls.isNullOrEmpty()) { if (book.downloadUrls.isNullOrEmpty()) {
@@ -224,6 +224,7 @@ object BookList {
searchBook.kind = analyzeRule.getStringList(ruleKind)?.joinToString(",") searchBook.kind = analyzeRule.getStringList(ruleKind)?.joinToString(",")
Debug.log(bookSource.bookSourceUrl, "└${searchBook.kind ?: ""}", log) Debug.log(bookSource.bookSourceUrl, "└${searchBook.kind ?: ""}", log)
} catch (e: Exception) { } catch (e: Exception) {
coroutineContext.ensureActive()
Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log) Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log)
} }
coroutineContext.ensureActive() coroutineContext.ensureActive()
@@ -231,7 +232,8 @@ object BookList {
try { try {
searchBook.wordCount = wordCountFormat(analyzeRule.getString(ruleWordCount)) searchBook.wordCount = wordCountFormat(analyzeRule.getString(ruleWordCount))
Debug.log(bookSource.bookSourceUrl, "└${searchBook.wordCount}", log) Debug.log(bookSource.bookSourceUrl, "└${searchBook.wordCount}", log)
} catch (e: java.lang.Exception) { } catch (e: Exception) {
coroutineContext.ensureActive()
Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log) Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log)
} }
coroutineContext.ensureActive() coroutineContext.ensureActive()
@@ -239,7 +241,8 @@ object BookList {
try { try {
searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter) searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter)
Debug.log(bookSource.bookSourceUrl, "└${searchBook.latestChapterTitle}", log) Debug.log(bookSource.bookSourceUrl, "└${searchBook.latestChapterTitle}", log)
} catch (e: java.lang.Exception) { } catch (e: Exception) {
coroutineContext.ensureActive()
Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log) Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log)
} }
coroutineContext.ensureActive() coroutineContext.ensureActive()
@@ -247,7 +250,8 @@ object BookList {
try { try {
searchBook.intro = HtmlFormatter.format(analyzeRule.getString(ruleIntro)) searchBook.intro = HtmlFormatter.format(analyzeRule.getString(ruleIntro))
Debug.log(bookSource.bookSourceUrl, "└${searchBook.intro}", log) Debug.log(bookSource.bookSourceUrl, "└${searchBook.intro}", log)
} catch (e: java.lang.Exception) { } catch (e: Exception) {
coroutineContext.ensureActive()
Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log) Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log)
} }
coroutineContext.ensureActive() coroutineContext.ensureActive()
@@ -259,7 +263,8 @@ object BookList {
} }
} }
Debug.log(bookSource.bookSourceUrl, "└${searchBook.coverUrl ?: ""}", log) Debug.log(bookSource.bookSourceUrl, "└${searchBook.coverUrl ?: ""}", log)
} catch (e: java.lang.Exception) { } catch (e: Exception) {
coroutineContext.ensureActive()
Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log) Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}", log)
} }
coroutineContext.ensureActive() coroutineContext.ensureActive()
@@ -199,6 +199,7 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
openOrCloseHelp(true) openOrCloseHelp(true)
initExploreKinds() initExploreKinds()
} }
R.id.menu_help -> showHelp("debugHelp") R.id.menu_help -> showHelp("debugHelp")
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)