mirror of
https://github.com/gedoor/legado.git
synced 2024-09-03 09:55:00 +08:00
源添加jsLib,未完成
This commit is contained in:
parent
d23d12044a
commit
5006433437
@ -1,5 +1,8 @@
|
|||||||
package io.legado.app.model
|
package io.legado.app.model
|
||||||
|
|
||||||
|
import com.script.SimpleBindings
|
||||||
|
import io.legado.app.constant.SCRIPT_ENGINE
|
||||||
|
import io.legado.app.help.rhino.RhinoScriptEngine
|
||||||
import io.legado.app.utils.MD5Utils
|
import io.legado.app.utils.MD5Utils
|
||||||
import org.mozilla.javascript.Scriptable
|
import org.mozilla.javascript.Scriptable
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
@ -8,12 +11,18 @@ object SharedJsScope {
|
|||||||
|
|
||||||
private val scopeMap = hashMapOf<String, WeakReference<Scriptable>>()
|
private val scopeMap = hashMapOf<String, WeakReference<Scriptable>>()
|
||||||
|
|
||||||
fun getScope(jsLib: String) {
|
fun getScope(jsLib: String): Scriptable {
|
||||||
val key = MD5Utils.md5Encode(jsLib)
|
val key = MD5Utils.md5Encode(jsLib)
|
||||||
var scope = scopeMap[key]?.get()
|
var scope = scopeMap[key]?.get()
|
||||||
if (scope == null) {
|
if (scope == null) {
|
||||||
|
val context = SCRIPT_ENGINE.getScriptContext(SimpleBindings())
|
||||||
|
scope = SCRIPT_ENGINE.getRuntimeScope(context)
|
||||||
|
RhinoScriptEngine.run {
|
||||||
|
it.evaluateString(scope, jsLib, "jsLib", 1, null)
|
||||||
|
}
|
||||||
|
scopeMap[key] = WeakReference(scope)
|
||||||
}
|
}
|
||||||
|
return scope
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user