From 22a664096324de531a90e49c4c6979761962e297 Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Tue, 27 Jan 2026 22:16:02 +0800 Subject: [PATCH] =?UTF-8?q?6.7.0=20-=20Alpha18=20-=20=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?ui.post=20=E6=96=B9=E6=B3=95=E5=9B=9E=E8=B0=83=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=B8=AD=E4=BA=A7=E7=94=9F=E5=BC=82=E5=B8=B8=E6=97=B6?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E9=9D=99=E9=BB=98=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changelog/lang_zh-Hans.json | 3 +- .../autojs/runtime/api/augment/ui/UI.kt | 66 +++++++++++-------- version.properties | 6 +- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json index d5e0d3ec..50643337 100644 --- a/.changelog/lang_zh-Hans.json +++ b/.changelog/lang_zh-Hans.json @@ -1,7 +1,7 @@ { "$data": { "v6.7.0": { - "released_date": "2026/01/26", + "released_date": "2026/01/27", "feature": [ "插件中心功能, 支持插件的安装/卸载/更新等操作 (入口: 主页抽屉按钮/主页标签页)", "Paddle OCR (PP-OCRv5) 插件, 用于光学字符识别", @@ -50,6 +50,7 @@ "fix": [ "notice 方法参数数量及类型限制错误 _[`issue #462`](http://issues.autojs6.com/462)_", "ui.R 属性 (getter) 无法正常使用的问题", + "ui.post 方法回调参数中产生异常时可能静默失败的问题", "isJavaClass/isJavaPackage 等全局方法无效的问题", "timers.keepAlive 方法 timeout 参数功能无效的问题", "floaty.window/rawWindow 方法无法接受字符串参数的问题 _[`issue #467`](http://issues.autojs6.com/467)_", 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 57842c22..c6d209b4 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 @@ -8,6 +8,8 @@ import android.view.WindowManager import androidx.core.graphics.drawable.toDrawable import org.autojs.autojs.annotation.RhinoFunctionBody import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface +import org.autojs.autojs.core.looper.Loopers +import org.autojs.autojs.core.looper.Timer import org.autojs.autojs.core.ui.JsViewHelper import org.autojs.autojs.core.ui.ViewExtras import org.autojs.autojs.core.ui.attribute.ViewAttributeDelegate @@ -20,20 +22,20 @@ import org.autojs.autojs.core.ui.nativeview.NativeView import org.autojs.autojs.core.ui.widget.JsListView import org.autojs.autojs.core.ui.widget.JsWebView import org.autojs.autojs.execution.ScriptExecuteActivity -import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish -import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief -import org.autojs.autojs.rhino.extension.AnyExtensions.jsSanitize -import org.autojs.autojs.rhino.extension.AnyExtensions.jsUnwrapped import org.autojs.autojs.rhino.ArgumentGuards.Companion.component1 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component2 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component3 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component4 -import org.autojs.autojs.rhino.extension.ScriptableExtensions.defineProp -import org.autojs.autojs.rhino.extension.ScriptableExtensions.prop -import org.autojs.autojs.rhino.extension.ScriptableObjectExtensions.inquire import org.autojs.autojs.rhino.ProxyObject.Companion.PROXY_GETTER_KEY import org.autojs.autojs.rhino.ProxyObject.Companion.PROXY_OBJECT_KEY import org.autojs.autojs.rhino.ProxyObject.Companion.PROXY_SETTER_KEY +import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish +import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief +import org.autojs.autojs.rhino.extension.AnyExtensions.jsSanitize +import org.autojs.autojs.rhino.extension.AnyExtensions.jsUnwrapped +import org.autojs.autojs.rhino.extension.ScriptableExtensions.defineProp +import org.autojs.autojs.rhino.extension.ScriptableExtensions.prop +import org.autojs.autojs.rhino.extension.ScriptableObjectExtensions.inquire import org.autojs.autojs.runtime.ScriptRuntime import org.autojs.autojs.runtime.api.augment.AugmentableProxy import org.autojs.autojs.runtime.api.augment.colors.ColorNativeObject @@ -108,7 +110,7 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt ::__inflate__.name, ::inflate.name, ::useAndroidLayout.name, - ::isUiThread.name, + ::isUiThread.name to AS_GLOBAL, ::post.name, ::layout.name, ::layoutFile.name, @@ -435,26 +437,21 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt return when { RhinoUtils.isUiThread() -> callFunction(scriptRuntime, action, arrayOf()) else -> { - var error: Exception? = null + var error: Throwable? = null var result: Any? = null val disposable = scriptRuntime.threads.disposable() scriptRuntime.uiHandler.post { try { result = callFunction(scriptRuntime, action, arrayOf()) - } catch (e: Exception) { - error = e + } catch (t: Throwable) { + error = t } finally { disposable.setAndNotify(true) } } disposable.blockedGet() - error?.let { - scriptRuntime.console.warn("${error.jsBrief()} occurred in `ui.run()`") - scriptRuntime.console.warn(it.message) - scriptRuntime.console.warn(it.stackTraceToString()) - throw it - } + error?.let { throw it } result } } @@ -479,9 +476,15 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt require(action is BaseFunction) { "Argument \"action\" ${action.jsBrief()} for ui.post must be a JavaScript Function" } + val loopers = scriptRuntime.loopers + val timer = scriptRuntime.timers.timerForCurrentThread + val waitId = timer?.let { loopers.waitWhenIdle() } ?: -1 + + val uiAction = wrapUiActionForPost(scriptRuntime, action, loopers, timer, waitId) + return when { - delay.isJsNullish() -> scriptRuntime.uiHandler.post(wrapUiAction(scriptRuntime, action)) - else -> scriptRuntime.uiHandler.postDelayed(wrapUiAction(scriptRuntime, action), coerceLongNumber(delay, 0L)) + delay.isJsNullish() -> scriptRuntime.uiHandler.post(uiAction) + else -> scriptRuntime.uiHandler.postDelayed(uiAction, coerceLongNumber(delay, 0L)) } } @@ -889,16 +892,23 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt callFunction(scriptRuntime.js_UiExt, scriptRuntime.topLevelScope, null, arrayOf(webView)) } - private fun wrapUiAction(scriptRuntime: ScriptRuntime, action: BaseFunction) = Runnable { - when { - !getActivity(scriptRuntime).isJsNullish() -> callFunction(scriptRuntime, action, scriptRuntime.topLevelScope, arrayOf()) - else -> withRhinoContext { cx -> - val scope = scriptRuntime.topLevelScope - val func = scope.prop("__exitIfError__") as BaseFunction - func.call(cx, scope, scope, arrayOf(newBaseFunction("action", { - callFunction(scriptRuntime, action, arrayOf()) - }, NOT_CONSTRUCTABLE))) + private fun wrapUiActionForPost(scriptRuntime: ScriptRuntime, action: BaseFunction, loopers: Loopers, timer: Timer?, waitId: Int) = Runnable { + try { + val isAutoJsUiMode = !getActivity(scriptRuntime).isJsNullish() + when { + isAutoJsUiMode -> { + callFunction(scriptRuntime, action, scriptRuntime.topLevelScope, arrayOf()) + } + else -> withRhinoContext { cx -> + val scope = scriptRuntime.topLevelScope + val exitIfErrorFunc = scope.prop("__exitIfError__") as BaseFunction + exitIfErrorFunc.call(cx, scope, scope, arrayOf(newBaseFunction("action", { + callFunction(scriptRuntime, action, arrayOf()) + }, NOT_CONSTRUCTABLE))) + } } + } finally { + timer?.postDelayed({ loopers.doNotWaitWhenIdle(waitId) }, 0) } } diff --git a/version.properties b/version.properties index a8504e4e..d0a404ef 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ -#Tue Jan 27 15:22:39 CST 2026 -BUILD_TIME=1769498559481 +#Tue Jan 27 22:05:54 CST 2026 +BUILD_TIME=1769522754078 COMPILE_SDK_VERSION=36 IMAGE_QUANT_CMAKE_VERSION=3.22.1 IMAGE_QUANT_NDK_VERSION=26.1.10909125 @@ -27,6 +27,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13 RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3 TARGET_SDK_VERSION=36 TARGET_SDK_VERSION_INRT=29 -VERSION_BUILD=3660 +VERSION_BUILD=3661 VERSION_NAME=6.7.0 Alpha18 VSCODE_EXT_REQUIRED_VERSION=1.0.13