优化
This commit is contained in:
@@ -97,21 +97,22 @@ interface BaseSource : JsExtensions {
|
|||||||
* 解析header规则
|
* 解析header规则
|
||||||
*/
|
*/
|
||||||
fun getHeaderMap(hasLoginHeader: Boolean = false) = HashMap<String, String>().apply {
|
fun getHeaderMap(hasLoginHeader: Boolean = false) = HashMap<String, String>().apply {
|
||||||
checkRhinoRecursiveCall()
|
|
||||||
header?.let {
|
header?.let {
|
||||||
GSON.fromJsonObject<Map<String, String>>(
|
val savedHeader = it
|
||||||
|
header = null
|
||||||
|
val json = try {
|
||||||
when {
|
when {
|
||||||
it.startsWith("@js:", true) -> evalJS(it.substring(4)).toString()
|
it.startsWith("@js:", true) -> evalJS(it.substring(4)).toString()
|
||||||
it.startsWith("<js>", true) -> evalJS(
|
it.startsWith("<js>", true) -> evalJS(
|
||||||
it.substring(
|
it.substring(4, it.lastIndexOf("<"))
|
||||||
4,
|
|
||||||
it.lastIndexOf("<")
|
|
||||||
)
|
|
||||||
).toString()
|
).toString()
|
||||||
|
|
||||||
else -> it
|
else -> it
|
||||||
}
|
}
|
||||||
).getOrNull()?.let { map ->
|
} finally {
|
||||||
|
header = savedHeader
|
||||||
|
}
|
||||||
|
GSON.fromJsonObject<Map<String, String>>(json).getOrNull()?.let { map ->
|
||||||
putAll(map)
|
putAll(map)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -397,7 +397,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
|
|
||||||
override fun observeLiveBus() {
|
override fun observeLiveBus() {
|
||||||
viewModel.upAdapterLiveData.observe(this) {
|
viewModel.upAdapterLiveData.observe(this) {
|
||||||
adapter.notifyItemRangeChanged(0, adapter.itemCount, it)
|
adapter.notifyItemRangeChanged(0, adapter.itemCount)
|
||||||
}
|
}
|
||||||
viewModel.searchFinishLiveData.observe(this) { isEmpty ->
|
viewModel.searchFinishLiveData.observe(this) { isEmpty ->
|
||||||
if (!isEmpty || viewModel.searchScope.isAll()) return@observe
|
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."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user