diff --git a/README.md b/README.md index b38baec5..7b0b17bc 100644 --- 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) diff --git a/common/build.gradle.kts b/common/build.gradle.kts index adb73235..d16b7f2e 100644 --- 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 index fb40a383..f8feddb5 100644 --- 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 index 8666115e..714ddc61 100644 --- 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]