feat(scripting): rhino android
This commit is contained in:
@@ -235,6 +235,7 @@ We do not collect any user information. However, please be aware that third-part
|
||||
- [coil](https://github.com/coil-kt/coil)
|
||||
- [Dobby](https://github.com/jmpews/Dobby)
|
||||
- [rhino](https://github.com/mozilla/rhino)
|
||||
- [rhino-android](https://github.com/F43nd1r/rhino-android)
|
||||
- [libsu](https://github.com/topjohnwu/libsu)
|
||||
</details>
|
||||
|
||||
|
||||
@@ -43,6 +43,9 @@ dependencies {
|
||||
implementation(libs.okhttp)
|
||||
implementation(libs.androidx.documentfile)
|
||||
implementation(libs.rhino)
|
||||
implementation(libs.rhino.android) {
|
||||
exclude(group = "org.mozilla", module = "rhino-runtime")
|
||||
}
|
||||
|
||||
compileOnly(libs.androidx.activity.ktx)
|
||||
compileOnly(platform(libs.androidx.compose.bom))
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
package me.rhunk.snapenhance.common.scripting.ktx
|
||||
|
||||
import com.faendir.rhino_android.RhinoAndroidHelper
|
||||
import org.mozilla.javascript.Context
|
||||
import org.mozilla.javascript.Function
|
||||
import org.mozilla.javascript.Scriptable
|
||||
import org.mozilla.javascript.ScriptableObject
|
||||
import org.mozilla.javascript.Wrapper
|
||||
import java.io.File
|
||||
|
||||
private val rhinoAndroidHelper = RhinoAndroidHelper(null as File?)
|
||||
|
||||
fun contextScope(f: Context.() -> Any?): Any? {
|
||||
val context = Context.enter()
|
||||
context.optimizationLevel = -1
|
||||
context.languageVersion = Context.VERSION_ES6
|
||||
val context = rhinoAndroidHelper.enterContext().apply {
|
||||
languageVersion = Context.VERSION_ES6
|
||||
}
|
||||
try {
|
||||
return context.f().let {
|
||||
if (it is Wrapper) {
|
||||
|
||||
@@ -24,6 +24,7 @@ junit = "5.10.2"
|
||||
material3 = "1.2.0"
|
||||
okhttp = "5.0.0-alpha.12"
|
||||
rhino = "1.7.14"
|
||||
rhino-android = "1.6.0"
|
||||
|
||||
|
||||
[libraries]
|
||||
@@ -53,6 +54,7 @@ okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhtt
|
||||
osmdroid-android = { group = "org.osmdroid", name = "osmdroid-android", version.ref = "osmdroid-android" }
|
||||
recyclerview = { group = "androidx.recyclerview", name = "recyclerview", version.ref = "recyclerview" }
|
||||
rhino = { module = "org.mozilla:rhino", version.ref = "rhino" }
|
||||
rhino-android = { group = "com.faendir.rhino", name = "rhino-android", version.ref = "rhino-android" }
|
||||
|
||||
|
||||
[plugins]
|
||||
|
||||
Reference in New Issue
Block a user