diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json index aadd2c9a..9b45d38c 100644 --- a/.changelog/lang_zh-Hans.json +++ b/.changelog/lang_zh-Hans.json @@ -7,6 +7,7 @@ "dx 库在 Android 7.x 无法正常使用的问题 _[`issue #293`](http://issues.autojs6.com/293)_", "ScriptRuntime 使用 require 引用内置模块时可能出现的同步状态异常 (试修) _[`issue #298`](http://issues.autojs6.com/298)_", "notice 模块缺失 getBuilder 等扩展方法的问题 _[`issue #301`](http://issues.autojs6.com/301)_", + "shizuku/shell 等方法无法接受字符串参数的问题 _[`issue #310`](http://issues.autojs6.com/310)_", "floaty.window/floaty.rawWindow 无法在子线程执行的问题", "ui.inflate 返回值丢失 attr/on/click 等原型方法的问题", "代码编辑器跳转到行尾时可能跳转到下一行起始位置的问题" diff --git a/app/src/main/java/org/autojs/autojs/core/floaty/RawWindow.kt b/app/src/main/java/org/autojs/autojs/core/floaty/RawWindow.kt index b12348e8..f89ef67e 100644 --- a/app/src/main/java/org/autojs/autojs/core/floaty/RawWindow.kt +++ b/app/src/main/java/org/autojs/autojs/core/floaty/RawWindow.kt @@ -22,7 +22,7 @@ class RawWindow(private val supplier: BaseResizableFloatyWindow.ViewSupplier) : private val mInflateException = VolatileDispose() - lateinit var contentView: View + var contentView: View? = null override fun onCreate(floatyService: FloatyService, windowManager: WindowManager) { try { diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/Floaty.kt b/app/src/main/java/org/autojs/autojs/runtime/api/Floaty.kt index 72f3396f..3cf30e3e 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/Floaty.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/Floaty.kt @@ -135,7 +135,9 @@ class Floaty(private val uiHandler: UiHandler, private val scriptRuntime: Script } fun findView(id: String?): View? { - return mWindow?.let { JsViewHelper.findViewByStringId(it.contentView, id) } + val win = mWindow ?: return null + val contentView = win.contentView ?: return null + return JsViewHelper.findViewByStringId(contentView, id) } val x: Int diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/ui/UI.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/ui/UI.kt index c7402a3a..621174f7 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/ui/UI.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/ui/UI.kt @@ -622,14 +622,15 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt private fun bindValueForApplyingAttribute(scriptRuntime: ScriptRuntime, value: String): String { val ctx = scriptRuntime.ui.bindingContext ?: return value + val niceCtx = ctx as? Scriptable + ?: Context.javaToJS(ctx, scriptRuntime.topLevelScope) as? Scriptable + ?: scriptRuntime.topLevelScope var tmp = value var i = -1 while (tmp.indexOf("{{", i + 1).also { i = it } >= 0) { val j = tmp.indexOf("}}", i + 1) - if (j < 0) { - return tmp - } - val evaluated = evalInContext(scriptRuntime, tmp.slice(i + 2 until j), ctx) + if (j < 0) return tmp + val evaluated = evalInContext(tmp.slice(i + 2 until j), niceCtx) tmp = tmp.slice(0 until i) + attrValueConvert(evaluated) + tmp.slice(j + 2 until tmp.length) } return tmp @@ -647,38 +648,39 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt else -> xml.toString() } - private fun evalInContext(scriptRuntime: ScriptRuntime, expression: String, ctx: Any): Any { - val scope = scriptRuntime.topLevelScope - return withRhinoContext { context -> - - // FIXME by SuperMonster003 on Jul 21, 2024. - // ! This code snippet is difficult to convert to Kotlin. - // ! The reason is that it contains JavaScript's "with" statement, - // ! and I haven't found a way to convert it in Rhino for now. - // ! Use the literal JavaScript code to ensure the functionality temporarily. - // ! zh-CN: - // ! 这段代码转换为 Kotlin 有些困难. - // ! 因为它包含了 JavaScript 的 "with" 语句, - // ! 我暂时没有找到对应的 Rhino 转换方式. - // ! 暂时先用 JavaScript 字面量代码的方式保证其功能性. - - // language=JavaScript - val script = """ - // noinspection JSUnusedLocalSymbols - function evalInContext(expression, ctx) { - return __exitIfError__(() => { - // noinspection WithStatementJS - with (ctx) { - return (/* @IIFE */ function () { - return eval(expression); - })(); - } - }); + /** + * This method is used to execute a given JavaScript expression within a specified context + * and return the result of that execution. + * + * zh-CN: 此方法用于在指定的上下文中执行所给定的 JavaScript 表达式, 并返回执行结果. + * + * The core logic of this method comes from the following JavaScript code. + * + * zh-CN: 该方法的核心逻辑来源于以下 JavaScript 代码: + * + * ```JavaScript + * function evalInContext(expression, ctx) { + * return __exitIfError__(() => { + * with (ctx) { + * return (/* @IIFE */ function () { + * return eval(expression); + * })(); + * } + * }); + * } + * ``` + * + * @param expression The JavaScript expression to evaluate as a string. (zh-CN: 用于执行的表达式.) + * @param ctx The context (scriptable scope) in which the expression should be evaluated. (zh-CN: 提供给参数 expression 的作用于上下文.) + * @return The result of evaluating the expression. (zh-CN: 参数 expression 执行结果.) + */ + private fun evalInContext(expression: String, ctx: Scriptable): Any? { + val iife = object : BaseFunction() { + override fun call(cx: Context, scope: Scriptable, thisObj: Scriptable, args: Array): Any? { + return cx.evaluateString(scope, expression, "", 1, null) } - """ - val func = context.evaluateString(scope, script, "evalInContext", 1, null) as BaseFunction - func.call(context, scope, scope, arrayOf(expression, ctx)) - }!! + } + return callFunction(iife, ctx, ctx, emptyArray()) } private fun initListView(scriptRuntime: ScriptRuntime, list: JsListView) { diff --git a/app/src/main/java/org/autojs/autojs/util/RhinoUtils.kt b/app/src/main/java/org/autojs/autojs/util/RhinoUtils.kt index 64317f84..201877db 100644 --- a/app/src/main/java/org/autojs/autojs/util/RhinoUtils.kt +++ b/app/src/main/java/org/autojs/autojs/util/RhinoUtils.kt @@ -22,6 +22,7 @@ import org.mozilla.javascript.AbstractEcmaObjectOperations import org.mozilla.javascript.BaseFunction import org.mozilla.javascript.BoundFunction import org.mozilla.javascript.Callable +import org.mozilla.javascript.ConsString import org.mozilla.javascript.Context import org.mozilla.javascript.ContinuationPending import org.mozilla.javascript.ImporterTopLevel @@ -265,8 +266,12 @@ object RhinoUtils { }!! @JvmStatic - fun unwrap(o: Any?) = when (o) { - is Wrapper -> o.unwrap() + fun unwrap(o: Any?): Any? = when (o) { + is String -> o + is ConsString -> o.toString() + is Number -> Context.toNumber(o) + is Boolean -> Context.toBoolean(o) + is Wrapper -> unwrap(o.unwrap()) is Unit -> UNDEFINED else -> o } diff --git a/version.properties b/version.properties index 8067396f..747b0a83 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ -#Wed Feb 05 20:51:07 CST 2025 -BUILD_TIME=1738759867266 +#Thu Feb 27 19:52:32 CST 2025 +BUILD_TIME=1740657152247 COMPILE_SDK_VERSION=34 JAVA_VERSION=23 JAVA_VERSION_MIN_RADICAL=0 @@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13 RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3 TARGET_SDK_VERSION=34 TARGET_SDK_VERSION_INRT=29 -VERSION_BUILD=2982 +VERSION_BUILD=2985 VERSION_NAME=6.6.2 Alpha2 VSCODE_EXT_REQUIRED_VERSION=1.0.8