6.6.1 - Alpha2 - 修复 automator.click/longClick 参数类型限制错误

This commit is contained in:
SuperMonster003
2024-12-08 00:32:28 +08:00
parent eaee908295
commit 394a391241
5 changed files with 79 additions and 23 deletions

View File

@@ -1,19 +1,20 @@
{ {
"$data": { "$data": {
"v6.6.1": { "v6.6.1": {
"released_date": "2024/12/07", "released_date": "2024/12/08",
"feature": [ "feature": [
"pinyin 模块, 用于汉语拼音转换 (参阅 项目文档 > [汉语拼音](https://docs.autojs6.com/#/pinyin))" "pinyin 模块, 用于汉语拼音转换 (参阅 项目文档 > [汉语拼音](https://docs.autojs6.com/#/pinyin))"
], ],
"fix": [ "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": [ "improvement": [
"脚本项目识别在 project.json 损坏情况下尽可能还原关键信息", "脚本项目识别在 project.json 损坏情况下尽可能还原关键信息",
"打包单文件时自动生成的包名后缀支持将简体中文自动转换为拼音", "打包单文件时自动生成的包名后缀支持将简体中文自动转换为拼音",
"支持更多的包名前缀省略形式 (如 RecyclerView, Snackbar 等)" "UI 元素及 className 相关选择器支持更多的包名前缀省略形式 (如 RecyclerView, Snackbar 等)"
] ]
}, },
"v6.6.0": { "v6.6.0": {

View File

@@ -11,6 +11,10 @@
<option name="SPACES_WITHIN_IMPORTS" value="true" /> <option name="SPACES_WITHIN_IMPORTS" value="true" />
</JSCodeStyleSettings> </JSCodeStyleSettings>
<JetCodeStyleSettings> <JetCodeStyleSettings>
<option name="LINE_BREAK_AFTER_MULTILINE_WHEN_ENTRY" value="false" />
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
<option name="ALLOW_TRAILING_COMMA" value="true" />
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings> </JetCodeStyleSettings>
<codeStyleSettings language="JAVA"> <codeStyleSettings language="JAVA">
@@ -18,6 +22,11 @@
</codeStyleSettings> </codeStyleSettings>
<codeStyleSettings language="kotlin"> <codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
<option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" />
<option name="BLOCK_COMMENT_AT_FIRST_COLUMN" value="false" />
<option name="LINE_COMMENT_ADD_SPACE" value="true" />
<option name="BLOCK_COMMENT_ADD_SPACE" value="true" />
<option name="LINE_COMMENT_ADD_SPACE_ON_REFORMAT" value="true" />
</codeStyleSettings> </codeStyleSettings>
</code_scheme> </code_scheme>
</component> </component>

View File

@@ -17,11 +17,12 @@ import org.autojs.autojs.extension.AnyExtensions.isJsNullish
import org.autojs.autojs.extension.AnyExtensions.isJsNumber import org.autojs.autojs.extension.AnyExtensions.isJsNumber
import org.autojs.autojs.extension.FlexibleArray import org.autojs.autojs.extension.FlexibleArray
import org.autojs.autojs.extension.ScriptableExtensions.prop 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.ScriptRuntime
import org.autojs.autojs.runtime.api.augment.Augmentable 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.ScriptException
import org.autojs.autojs.runtime.exception.ShouldNeverHappenException 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
import org.autojs.autojs.util.RhinoUtils.coerceIntNumber import org.autojs.autojs.util.RhinoUtils.coerceIntNumber
import org.autojs.autojs.util.RhinoUtils.coerceLongNumber 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.ImporterTopLevel
import org.mozilla.javascript.NativeJavaObject import org.mozilla.javascript.NativeJavaObject
import org.mozilla.javascript.NativeObject import org.mozilla.javascript.NativeObject
import android.graphics.Point as AndroidPoint
import org.opencv.core.Point as OpencvPoint
@Suppress("unused", "SameParameterValue", "UNUSED_PARAMETER") @Suppress("unused", "SameParameterValue", "UNUSED_PARAMETER")
class Automator(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) { class Automator(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
@@ -86,10 +89,10 @@ class Automator(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
*/ */
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface
fun click(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Boolean = unwrapArguments(args) { fun click(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Boolean = unwrapArguments(args) { argList ->
require(it.isNotEmpty()) { "Arguments cannot be empty for automator.click" } require(argList.isNotEmpty()) { "Arguments cannot be empty for automator.click" }
when (it.size) { when (argList.size) {
1 -> when (val o = it[0]) { 1 -> when (val o = argList[0]) {
is Rect -> return@unwrapArguments click(scriptRuntime, arrayOf(o.centerX(), o.centerY())) is Rect -> return@unwrapArguments click(scriptRuntime, arrayOf(o.centerX(), o.centerY()))
is UiObject -> return@unwrapArguments when { is UiObject -> return@unwrapArguments when {
o.clickable() -> o.click() o.clickable() -> o.click()
@@ -102,32 +105,75 @@ class Automator(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
if (y.isJsNullish()) return@unwrapArguments click(scriptRuntime, arrayOf(x, x)) 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 -> { 2 -> {
val (x, y) = it val (x, y) = argList
return@unwrapArguments scriptRuntime.automator.click(coerceIntNumber(x), coerceIntNumber(y)) 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: * TypeScript Declarations:
* - longClick(x: number, y: number): boolean * - longClick(x: number, y: number): boolean
* - longClick(point: [x: number, y: number]): boolean
* - longClick(text: string, index?: number): boolean * - longClick(text: string, index?: number): boolean
* - longClick(left: number, top: number, right: number, bottom: number): boolean * - longClick(left: number, top: number, right: number, bottom: number): boolean
* - longClick(widget: UiObject): boolean
* - longClick(bounds: Rect): boolean
*/ */
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface
fun longClick(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Boolean = unwrapArguments(args) { fun longClick(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Boolean = unwrapArguments(args) { argList ->
require(it.isNotEmpty()) { "Arguments cannot be empty for automator.longClick" } require(argList.isNotEmpty()) { "Arguments cannot be empty for automator.longClick" }
when (it.size) { when (argList.size) {
2 -> { 1 -> when (val o = argList[0]) {
val (x, y) = it is Rect -> return@unwrapArguments longClick(scriptRuntime, arrayOf(o.centerX(), o.centerY()))
scriptRuntime.automator.longClick(coerceIntNumber(x), coerceIntNumber(y)) 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)
} }
/** /**

View File

@@ -459,11 +459,11 @@ object RhinoUtils {
fun coerceNumber(o: Any?, def: Number? = null): Double = when { fun coerceNumber(o: Any?, def: Number? = null): Double = when {
!o.isJsNullish() -> Context.toNumber(o).also { !o.isJsNullish() -> Context.toNumber(o).also {
require(!it.isNaN() || def == RhinoScriptRuntime.NaN) { 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() !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 @JvmStatic

View File

@@ -1,5 +1,5 @@
#Sat Dec 07 17:46:27 CST 2024 #Sun Dec 08 00:27:05 CST 2024
BUILD_TIME=1733564787201 BUILD_TIME=1733588825270
COMPILE_SDK_VERSION=34 COMPILE_SDK_VERSION=34
JAVA_VERSION=23 JAVA_VERSION=23
JAVA_VERSION_MIN_RADICAL=0 JAVA_VERSION_MIN_RADICAL=0
@@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3 RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
TARGET_SDK_VERSION=34 TARGET_SDK_VERSION=34
TARGET_SDK_VERSION_INRT=29 TARGET_SDK_VERSION_INRT=29
VERSION_BUILD=2896 VERSION_BUILD=2897
VERSION_NAME=6.6.1 Alpha2 VERSION_NAME=6.6.1 Alpha2
VSCODE_EXT_REQUIRED_VERSION=1.0.8 VSCODE_EXT_REQUIRED_VERSION=1.0.8