源添加jsLib,未完成
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user