commit fbd683251a7e2d92312996fbc75ea5e6651ad5ed
parent 174dca6754c27b100065674f10949b944a8c29b2
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Sun, 28 Apr 2024 19:03:44 +0200

feat(scripting): rhino android

Diffstat:
MREADME.md | 1+
Mcommon/build.gradle.kts | 3+++
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/scripting/ktx/RhinoKtx.kt | 10+++++++---
Mgradle/libs.versions.toml | 2++
4 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md @@ -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> diff --git a/common/build.gradle.kts b/common/build.gradle.kts @@ -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)) diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/ktx/RhinoKtx.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/ktx/RhinoKtx.kt @@ -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) { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml @@ -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]