feat(scripting): rhino android

This commit is contained in:
rhunk
2024-04-28 19:03:44 +02:00
parent 174dca6754
commit fbd683251a
4 changed files with 13 additions and 3 deletions

View File

@@ -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>

View File

@@ -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))

View File

@@ -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) {

View File

@@ -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]