This commit is contained in:
Horis
2024-07-09 23:12:34 +08:00
parent 5631edf467
commit 62bffb600d
3 changed files with 9 additions and 34 deletions
@@ -97,21 +97,22 @@ interface BaseSource : JsExtensions {
* 解析header规则
*/
fun getHeaderMap(hasLoginHeader: Boolean = false) = HashMap<String, String>().apply {
checkRhinoRecursiveCall()
header?.let {
GSON.fromJsonObject<Map<String, String>>(
val savedHeader = it
header = null
val json = try {
when {
it.startsWith("@js:", true) -> evalJS(it.substring(4)).toString()
it.startsWith("<js>", true) -> evalJS(
it.substring(
4,
it.lastIndexOf("<")
)
it.substring(4, it.lastIndexOf("<"))
).toString()
else -> it
}
).getOrNull()?.let { map ->
} finally {
header = savedHeader
}
GSON.fromJsonObject<Map<String, String>>(json).getOrNull()?.let { map ->
putAll(map)
}
}
@@ -397,7 +397,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
override fun observeLiveBus() {
viewModel.upAdapterLiveData.observe(this) {
adapter.notifyItemRangeChanged(0, adapter.itemCount, it)
adapter.notifyItemRangeChanged(0, adapter.itemCount)
}
viewModel.searchFinishLiveData.observe(this) { isEmpty ->
if (!isEmpty || viewModel.searchScope.isAll()) return@observe
@@ -1,26 +0,0 @@
package io.legado.app.utils
import org.mozilla.javascript.Context
private val enterCountField by lazy {
Context::class.java.getDeclaredField("enterCount").apply {
isAccessible = true
}
}
fun Context?.getEnterCount(): Int {
this ?: return 0
return enterCountField.get(this) as Int
}
fun checkRhinoRecursiveCall() {
check(Context.getCurrentContext().getEnterCount() <= 1) {
"Rhino recursive call detected."
}
}
fun checkRhinoCall() {
check(Context.getCurrentContext() == null) {
"Rhino call detected."
}
}