diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json
index 14cfb9f0..7ce9300c 100644
--- a/.changelog/lang_zh-Hans.json
+++ b/.changelog/lang_zh-Hans.json
@@ -1,19 +1,20 @@
{
"$data": {
"v6.6.1": {
- "released_date": "2024/12/07",
+ "released_date": "2024/12/08",
"feature": [
"pinyin 模块, 用于汉语拼音转换 (参阅 项目文档 > [汉语拼音](https://docs.autojs6.com/#/pinyin))"
],
"fix": [
"部分环境因回退版本过低而无法正常编译项目的问题",
"调用不存在的方法时可能出现的 \"非原始类型值\" 异常",
- "部分设备无法正常添加脚本快捷方式的问题 (试修) _[`issue #221`](http://issues.autojs6.com/221)_"
+ "部分设备无法正常添加脚本快捷方式的问题 (试修) _[`issue #221`](http://issues.autojs6.com/221)_",
+ "automator.click/longClick 方法参数类型限制错误 _[`issue #275`](http://issues.autojs6.com/275)_"
],
"improvement": [
"脚本项目识别在 project.json 损坏情况下尽可能还原关键信息",
"打包单文件时自动生成的包名后缀支持将简体中文自动转换为拼音",
- "支持更多的包名前缀省略形式 (如 RecyclerView, Snackbar 等)"
+ "UI 元素及 className 相关选择器支持更多的包名前缀省略形式 (如 RecyclerView, Snackbar 等)"
]
},
"v6.6.0": {
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index ee85bf28..c5b5c5e4 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -11,6 +11,10 @@
+
+
+
+
@@ -18,6 +22,11 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/automator/Automator.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/automator/Automator.kt
index edecc6ab..7e1e275f 100644
--- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/automator/Automator.kt
+++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/automator/Automator.kt
@@ -17,11 +17,12 @@ import org.autojs.autojs.extension.AnyExtensions.isJsNullish
import org.autojs.autojs.extension.AnyExtensions.isJsNumber
import org.autojs.autojs.extension.FlexibleArray
import org.autojs.autojs.extension.ScriptableExtensions.prop
+import org.autojs.autojs.extension.ScriptableObjectExtensions.inquire
import org.autojs.autojs.runtime.ScriptRuntime
import org.autojs.autojs.runtime.api.augment.Augmentable
-import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException
import org.autojs.autojs.runtime.exception.ScriptException
import org.autojs.autojs.runtime.exception.ShouldNeverHappenException
+import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException
import org.autojs.autojs.util.RhinoUtils
import org.autojs.autojs.util.RhinoUtils.coerceIntNumber
import org.autojs.autojs.util.RhinoUtils.coerceLongNumber
@@ -35,6 +36,8 @@ import org.mozilla.javascript.Context
import org.mozilla.javascript.ImporterTopLevel
import org.mozilla.javascript.NativeJavaObject
import org.mozilla.javascript.NativeObject
+import android.graphics.Point as AndroidPoint
+import org.opencv.core.Point as OpencvPoint
@Suppress("unused", "SameParameterValue", "UNUSED_PARAMETER")
class Automator(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
@@ -86,10 +89,10 @@ class Automator(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
*/
@JvmStatic
@RhinoRuntimeFunctionInterface
- fun click(scriptRuntime: ScriptRuntime, args: Array): Boolean = unwrapArguments(args) {
- require(it.isNotEmpty()) { "Arguments cannot be empty for automator.click" }
- when (it.size) {
- 1 -> when (val o = it[0]) {
+ fun click(scriptRuntime: ScriptRuntime, args: Array): Boolean = unwrapArguments(args) { argList ->
+ require(argList.isNotEmpty()) { "Arguments cannot be empty for automator.click" }
+ when (argList.size) {
+ 1 -> when (val o = argList[0]) {
is Rect -> return@unwrapArguments click(scriptRuntime, arrayOf(o.centerX(), o.centerY()))
is UiObject -> return@unwrapArguments when {
o.clickable() -> o.click()
@@ -102,32 +105,75 @@ class Automator(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
if (y.isJsNullish()) return@unwrapArguments click(scriptRuntime, arrayOf(x, x))
}
}
+ is AndroidPoint -> return@unwrapArguments click(scriptRuntime, arrayOf(o.x, o.y))
+ is OpencvPoint -> return@unwrapArguments click(scriptRuntime, arrayOf(o.x, o.y))
+ is NativeObject -> {
+ val x = o.inquire("x", ::coerceIntNumber) ?: throw IllegalStateException(
+ "Property \"x\" for automator.click must be a valid number",
+ )
+ val y = o.inquire("y", ::coerceIntNumber) ?: throw IllegalStateException(
+ "Property \"y\" for automator.click must be a valid number",
+ )
+ return@unwrapArguments click(scriptRuntime, arrayOf(x, y))
+ }
}
2 -> {
- val (x, y) = it
- return@unwrapArguments scriptRuntime.automator.click(coerceIntNumber(x), coerceIntNumber(y))
+ val (x, y) = argList
+ if (x.isJsNumber() && y.isJsNumber()) {
+ return@unwrapArguments scriptRuntime.automator.click(coerceIntNumber(x), coerceIntNumber(y))
+ }
}
}
- return@unwrapArguments performAction(scriptRuntime, fun(target: ActionTarget) = scriptRuntime.automator.click(target), it)
+ return@unwrapArguments performAction(scriptRuntime, fun(target: ActionTarget) = scriptRuntime.automator.click(target), argList)
}
/**
* TypeScript Declarations:
* - longClick(x: number, y: number): boolean
+ * - longClick(point: [x: number, y: number]): boolean
* - longClick(text: string, index?: number): boolean
* - longClick(left: number, top: number, right: number, bottom: number): boolean
+ * - longClick(widget: UiObject): boolean
+ * - longClick(bounds: Rect): boolean
*/
@JvmStatic
@RhinoRuntimeFunctionInterface
- fun longClick(scriptRuntime: ScriptRuntime, args: Array): Boolean = unwrapArguments(args) {
- require(it.isNotEmpty()) { "Arguments cannot be empty for automator.longClick" }
- when (it.size) {
- 2 -> {
- val (x, y) = it
- scriptRuntime.automator.longClick(coerceIntNumber(x), coerceIntNumber(y))
+ fun longClick(scriptRuntime: ScriptRuntime, args: Array): Boolean = unwrapArguments(args) { argList ->
+ require(argList.isNotEmpty()) { "Arguments cannot be empty for automator.longClick" }
+ when (argList.size) {
+ 1 -> when (val o = argList[0]) {
+ is Rect -> return@unwrapArguments longClick(scriptRuntime, arrayOf(o.centerX(), o.centerY()))
+ is UiObject -> return@unwrapArguments when {
+ o.longClickable() -> o.longClick()
+ else -> longClick(scriptRuntime, arrayOf(o.bounds()))
+ }
+ is List<*> -> {
+ val (x, y) = o
+ if (x.isJsNumber()) {
+ if (y.isJsNumber()) return@unwrapArguments longClick(scriptRuntime, arrayOf(x, y))
+ if (y.isJsNullish()) return@unwrapArguments longClick(scriptRuntime, arrayOf(x, x))
+ }
+ }
+ is AndroidPoint -> return@unwrapArguments longClick(scriptRuntime, arrayOf(o.x, o.y))
+ is OpencvPoint -> return@unwrapArguments longClick(scriptRuntime, arrayOf(o.x, o.y))
+ is NativeObject -> {
+ val x = o.inquire("x", ::coerceIntNumber) ?: throw IllegalStateException(
+ "Property \"x\" for automator.longClick must be a valid number",
+ )
+ val y = o.inquire("y", ::coerceIntNumber) ?: throw IllegalStateException(
+ "Property \"y\" for automator.longClick must be a valid number",
+ )
+ return@unwrapArguments longClick(scriptRuntime, arrayOf(x, y))
+ }
+ }
+ 2 -> {
+ val (x, y) = argList
+ if (x.isJsNumber() && y.isJsNumber()) {
+ return@unwrapArguments scriptRuntime.automator.longClick(coerceIntNumber(x), coerceIntNumber(y))
+ }
}
- else -> performAction(scriptRuntime, fun(target: ActionTarget) = scriptRuntime.automator.longClick(target), it)
}
+ return@unwrapArguments performAction(scriptRuntime, fun(target: ActionTarget) = scriptRuntime.automator.longClick(target), argList)
}
/**
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 0f79a71b..f7ae205b 100644
--- a/app/src/main/java/org/autojs/autojs/util/RhinoUtils.kt
+++ b/app/src/main/java/org/autojs/autojs/util/RhinoUtils.kt
@@ -459,11 +459,11 @@ object RhinoUtils {
fun coerceNumber(o: Any?, def: Number? = null): Double = when {
!o.isJsNullish() -> Context.toNumber(o).also {
require(!it.isNaN() || def == RhinoScriptRuntime.NaN) {
- "Failed to coerce ${o.jsBrief()} into a number"
+ "Failed to coerce ${o.jsBrief()} into a valid number"
}
}
!def.isJsNullish() -> def!!.toDouble()
- else -> throw IllegalArgumentException("Failed to coerce nullish (${o.jsSpecies()}) into a number")
+ else -> throw IllegalArgumentException("Failed to coerce nullish (${o.jsSpecies()}) into a valid number")
}
@JvmStatic
diff --git a/version.properties b/version.properties
index f1f9e0ff..0e1e43e3 100644
--- a/version.properties
+++ b/version.properties
@@ -1,5 +1,5 @@
-#Sat Dec 07 17:46:27 CST 2024
-BUILD_TIME=1733564787201
+#Sun Dec 08 00:27:05 CST 2024
+BUILD_TIME=1733588825270
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=2896
+VERSION_BUILD=2897
VERSION_NAME=6.6.1 Alpha2
VSCODE_EXT_REQUIRED_VERSION=1.0.8