From 9477f5b78a8c297d548ad851c9fc3f235d646bc3 Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Sat, 12 Apr 2025 21:17:11 +0800 Subject: [PATCH] =?UTF-8?q?6.6.2=20-=20Alpha6=20-=20=E4=BF=AE=E5=A4=8D=20f?= =?UTF-8?q?loaty.getClip=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changelog/lang_zh-Hans.json | 4 +- .readme/README-zh-Hans.md | 2 + README.md | 2 + .../main/assets-app/doc/CHANGELOG-zh-Hans.md | 2 + app/src/main/assets-app/doc/CHANGELOG.md | 2 + .../org/autojs/autojs/runtime/api/Floaty.kt | 43 +++++++++++++------ .../runtime/api/augment/floaty/Floaty.kt | 8 ++-- .../runtime/api/augment/global/Global.kt | 10 ++++- version.properties | 6 +-- 9 files changed, 58 insertions(+), 21 deletions(-) diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json index 16e27426..106d166c 100644 --- a/.changelog/lang_zh-Hans.json +++ b/.changelog/lang_zh-Hans.json @@ -18,6 +18,7 @@ "colors.pixel 方法无法接受单通道图像参数的问题 _[`issue #350`](http://issues.autojs6.com/350)_", "engines.execScript/execScriptFile 等方法执行脚本时默认工作路径异常", "floaty.window/floaty.rawWindow 无法在子线程执行的问题", + "floaty.getClip 可能无法正常获取剪切板内容的问题", "ui.inflate 返回值丢失 attr/on/click 等原型方法的问题", "布局分析页面生成代码时可能导致应用崩溃的问题 _[`issue #288`](http://issues.autojs6.com/288)_", "打包应用无法正常使用 shizuku 模块的问题 _[`issue #227`](http://issues.autojs6.com/227)_ _[`issue #231`](http://issues.autojs6.com/231)_ _[`issue #284`](http://issues.autojs6.com/284)_ _[`issue #287`](http://issues.autojs6.com/287)_ _[`issue #304`](http://issues.autojs6.com/304)_" , @@ -41,7 +42,8 @@ "APK 文件类型信息对话框增加文件大小与签名方案信息", "APK 文件类型信息对话框增加点击监听器支持文本复制与应用详情跳转", "尝试恢复 com.stardust 前缀包以便提升代码兼容性 _[`issue #290`](http://issues.autojs6.com/290)_", - "floaty.window/floaty.rawWindow 同时支持主线程和子线程执行" + "floaty.window/floaty.rawWindow 同时支持主线程和子线程执行", + "getClip 全局方法适时借助 floaty.getClip 方法以提升兼容性" ], "dependency": [ "升级 Gradle Compile 版本 34 -> 35", diff --git a/.readme/README-zh-Hans.md b/.readme/README-zh-Hans.md index b47c19af..4ada636c 100644 --- a/.readme/README-zh-Hans.md +++ b/.readme/README-zh-Hans.md @@ -172,6 +172,7 @@ AutoJs6 在 Auto.js 最终项目的基础上, 于 `2021/12/01` 进行二次开 * `修复` colors.pixel 方法无法接受单通道图像参数的问题 _[`issue #350`](http://issues.autojs6.com/350)_ * `修复` engines.execScript/execScriptFile 等方法执行脚本时默认工作路径异常 * `修复` floaty.window/floaty.rawWindow 无法在子线程执行的问题 +* `修复` floaty.getClip 可能无法正常获取剪切板内容的问题 * `修复` ui.inflate 返回值丢失 attr/on/click 等原型方法的问题 * `修复` 布局分析页面生成代码时可能导致应用崩溃的问题 _[`issue #288`](http://issues.autojs6.com/288)_ * `修复` 打包应用无法正常使用 shizuku 模块的问题 _[`issue #227`](http://issues.autojs6.com/227)_ _[`issue #231`](http://issues.autojs6.com/231)_ _[`issue #284`](http://issues.autojs6.com/284)_ _[`issue #287`](http://issues.autojs6.com/287)_ _[`issue #304`](http://issues.autojs6.com/304)_ @@ -194,6 +195,7 @@ AutoJs6 在 Auto.js 最终项目的基础上, 于 `2021/12/01` 进行二次开 * `优化` APK 文件类型信息对话框增加点击监听器支持文本复制与应用详情跳转 * `优化` 尝试恢复 com.stardust 前缀包以便提升代码兼容性 _[`issue #290`](http://issues.autojs6.com/290)_ * `优化` floaty.window/floaty.rawWindow 同时支持主线程和子线程执行 +* `优化` getClip 全局方法适时借助 floaty.getClip 方法以提升兼容性 * `优化` 部分依赖或本地库版本调整 _[`CHANGELOG.md`](http://project.autojs6.com/blob/master/app/src/main/assets-app/doc/CHANGELOG.md#v662)_ # v6.6.1 diff --git a/README.md b/README.md index b47c19af..4ada636c 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,7 @@ AutoJs6 在 Auto.js 最终项目的基础上, 于 `2021/12/01` 进行二次开 * `修复` colors.pixel 方法无法接受单通道图像参数的问题 _[`issue #350`](http://issues.autojs6.com/350)_ * `修复` engines.execScript/execScriptFile 等方法执行脚本时默认工作路径异常 * `修复` floaty.window/floaty.rawWindow 无法在子线程执行的问题 +* `修复` floaty.getClip 可能无法正常获取剪切板内容的问题 * `修复` ui.inflate 返回值丢失 attr/on/click 等原型方法的问题 * `修复` 布局分析页面生成代码时可能导致应用崩溃的问题 _[`issue #288`](http://issues.autojs6.com/288)_ * `修复` 打包应用无法正常使用 shizuku 模块的问题 _[`issue #227`](http://issues.autojs6.com/227)_ _[`issue #231`](http://issues.autojs6.com/231)_ _[`issue #284`](http://issues.autojs6.com/284)_ _[`issue #287`](http://issues.autojs6.com/287)_ _[`issue #304`](http://issues.autojs6.com/304)_ @@ -194,6 +195,7 @@ AutoJs6 在 Auto.js 最终项目的基础上, 于 `2021/12/01` 进行二次开 * `优化` APK 文件类型信息对话框增加点击监听器支持文本复制与应用详情跳转 * `优化` 尝试恢复 com.stardust 前缀包以便提升代码兼容性 _[`issue #290`](http://issues.autojs6.com/290)_ * `优化` floaty.window/floaty.rawWindow 同时支持主线程和子线程执行 +* `优化` getClip 全局方法适时借助 floaty.getClip 方法以提升兼容性 * `优化` 部分依赖或本地库版本调整 _[`CHANGELOG.md`](http://project.autojs6.com/blob/master/app/src/main/assets-app/doc/CHANGELOG.md#v662)_ # v6.6.1 diff --git a/app/src/main/assets-app/doc/CHANGELOG-zh-Hans.md b/app/src/main/assets-app/doc/CHANGELOG-zh-Hans.md index 2431c723..7f0bd8c4 100644 --- a/app/src/main/assets-app/doc/CHANGELOG-zh-Hans.md +++ b/app/src/main/assets-app/doc/CHANGELOG-zh-Hans.md @@ -21,6 +21,7 @@ * `修复` colors.pixel 方法无法接受单通道图像参数的问题 _[`issue #350`](http://issues.autojs6.com/350)_ * `修复` engines.execScript/execScriptFile 等方法执行脚本时默认工作路径异常 * `修复` floaty.window/floaty.rawWindow 无法在子线程执行的问题 +* `修复` floaty.getClip 可能无法正常获取剪切板内容的问题 * `修复` ui.inflate 返回值丢失 attr/on/click 等原型方法的问题 * `修复` 布局分析页面生成代码时可能导致应用崩溃的问题 _[`issue #288`](http://issues.autojs6.com/288)_ * `修复` 打包应用无法正常使用 shizuku 模块的问题 _[`issue #227`](http://issues.autojs6.com/227)_ _[`issue #231`](http://issues.autojs6.com/231)_ _[`issue #284`](http://issues.autojs6.com/284)_ _[`issue #287`](http://issues.autojs6.com/287)_ _[`issue #304`](http://issues.autojs6.com/304)_ @@ -43,6 +44,7 @@ * `优化` APK 文件类型信息对话框增加点击监听器支持文本复制与应用详情跳转 * `优化` 尝试恢复 com.stardust 前缀包以便提升代码兼容性 _[`issue #290`](http://issues.autojs6.com/290)_ * `优化` floaty.window/floaty.rawWindow 同时支持主线程和子线程执行 +* `优化` getClip 全局方法适时借助 floaty.getClip 方法以提升兼容性 * `依赖` 升级 Gradle Compile 版本 34 -> 35 * `依赖` 升级 Gradle 版本 8.12 -> 8.14-rc-1 * `依赖` 升级 Rhino 版本 1.8.0-SNAPSHOT -> 1.8.1-SNAPSHOT diff --git a/app/src/main/assets-app/doc/CHANGELOG.md b/app/src/main/assets-app/doc/CHANGELOG.md index 2431c723..7f0bd8c4 100644 --- a/app/src/main/assets-app/doc/CHANGELOG.md +++ b/app/src/main/assets-app/doc/CHANGELOG.md @@ -21,6 +21,7 @@ * `修复` colors.pixel 方法无法接受单通道图像参数的问题 _[`issue #350`](http://issues.autojs6.com/350)_ * `修复` engines.execScript/execScriptFile 等方法执行脚本时默认工作路径异常 * `修复` floaty.window/floaty.rawWindow 无法在子线程执行的问题 +* `修复` floaty.getClip 可能无法正常获取剪切板内容的问题 * `修复` ui.inflate 返回值丢失 attr/on/click 等原型方法的问题 * `修复` 布局分析页面生成代码时可能导致应用崩溃的问题 _[`issue #288`](http://issues.autojs6.com/288)_ * `修复` 打包应用无法正常使用 shizuku 模块的问题 _[`issue #227`](http://issues.autojs6.com/227)_ _[`issue #231`](http://issues.autojs6.com/231)_ _[`issue #284`](http://issues.autojs6.com/284)_ _[`issue #287`](http://issues.autojs6.com/287)_ _[`issue #304`](http://issues.autojs6.com/304)_ @@ -43,6 +44,7 @@ * `优化` APK 文件类型信息对话框增加点击监听器支持文本复制与应用详情跳转 * `优化` 尝试恢复 com.stardust 前缀包以便提升代码兼容性 _[`issue #290`](http://issues.autojs6.com/290)_ * `优化` floaty.window/floaty.rawWindow 同时支持主线程和子线程执行 +* `优化` getClip 全局方法适时借助 floaty.getClip 方法以提升兼容性 * `依赖` 升级 Gradle Compile 版本 34 -> 35 * `依赖` 升级 Gradle 版本 8.12 -> 8.14-rc-1 * `依赖` 升级 Rhino 版本 1.8.0-SNAPSHOT -> 1.8.1-SNAPSHOT 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 3cf30e3e..210c3d10 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 @@ -5,8 +5,10 @@ import android.content.Intent import android.view.ContextThemeWrapper import android.view.View import android.view.ViewGroup +import android.widget.FrameLayout import kotlinx.coroutines.Runnable import org.autojs.autojs.annotation.ScriptInterface +import org.autojs.autojs.concurrent.VolatileDispose import org.autojs.autojs.core.floaty.BaseResizableFloatyWindow import org.autojs.autojs.core.floaty.RawWindow import org.autojs.autojs.core.ui.JsViewHelper @@ -18,14 +20,12 @@ import org.autojs.autojs.runtime.exception.ScriptInterruptedException import org.autojs.autojs.tool.UiHandler import org.autojs.autojs.ui.enhancedfloaty.FloatyService import org.autojs.autojs.util.RhinoUtils.NOT_CONSTRUCTABLE +import org.autojs.autojs.util.RhinoUtils.isMainThread import org.autojs.autojs.util.RhinoUtils.isUiThread import org.autojs.autojs.util.RhinoUtils.newBaseFunction import org.autojs.autojs.util.ViewUtils.setViewMeasure import org.autojs.autojs6.R import java.util.concurrent.CopyOnWriteArraySet -import java.util.concurrent.CountDownLatch -import java.util.concurrent.TimeUnit -import kotlin.math.max /** * Created by Stardust on Dec 5, 2017. @@ -47,7 +47,7 @@ class Floaty(private val uiHandler: UiHandler, private val scriptRuntime: Script return JsResizableWindow(supplier).also { addWindow(it) } } - fun window(view: View): JsResizableWindow = window(object : BaseResizableFloatyWindow.ViewSupplier { + fun window(view: View) = window(object : BaseResizableFloatyWindow.ViewSupplier { override fun inflate(context: Context, parent: ViewGroup?) = view }) @@ -60,7 +60,7 @@ class Floaty(private val uiHandler: UiHandler, private val scriptRuntime: Script return JsRawWindow(supplier).also { addWindow(it) } } - fun rawWindow(view: View) = JsRawWindow(object : BaseResizableFloatyWindow.ViewSupplier { + fun rawWindow(view: View) = rawWindow(object : BaseResizableFloatyWindow.ViewSupplier { override fun inflate(context: Context, parent: ViewGroup?) = view }) @@ -96,18 +96,37 @@ class Floaty(private val uiHandler: UiHandler, private val scriptRuntime: Script } @ScriptInterface - fun getClip(delay: Long = 0L): String { + fun getClip(maxDelayAfterWindowReady: Long = 500L): String { val start = System.currentTimeMillis() - val timeoutForAttachedToWindowManager: Long = 2_000 - val latch = CountDownLatch(1) - val win = window(View(mContext).apply { visibility = View.INVISIBLE }) - UI.postRhinoRuntime(scriptRuntime, newBaseFunction("action", { + val timeoutForAttachedToWindowManager = 1000L + val view = FrameLayout(mContext) + val win = rawWindow(view) + UI.runRhinoRuntime(scriptRuntime, newBaseFunction("action", { while (System.currentTimeMillis() - start < timeoutForAttachedToWindowManager) { if (runCatching { win.requestFocus() }.isSuccess) break } }, NOT_CONSTRUCTABLE)) - latch.await(max(0, delay - (System.currentTimeMillis() - start)), TimeUnit.MILLISECONDS) - return scriptRuntime.clip.also { win.close() } + val getClipboardData = { + val getter = { scriptRuntime.clip.also { win.close() } } + val startTime = System.currentTimeMillis() + var result = getter() + while (System.currentTimeMillis() - startTime < maxDelayAfterWindowReady) { + if (result.isNotBlank()) break + Thread.sleep(10) + result = getter() + } + result + } + return when { + isMainThread() -> { + getClipboardData() + } + else -> { + val result = VolatileDispose() + scriptRuntime.uiHandler.post { result.setAndNotify(getClipboardData()) } + result.blockedGetOrThrow(ScriptInterruptedException::class.java) + } + } } interface JsWindow { diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/floaty/Floaty.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/floaty/Floaty.kt index c5f013c2..590af94b 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/floaty/Floaty.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/floaty/Floaty.kt @@ -85,10 +85,10 @@ class Floaty(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) { @JvmStatic @RhinoRuntimeFunctionInterface fun getClip(scriptRuntime: ScriptRuntime, args: Array): String = ensureArgumentsAtMost(args, 1) { argList -> - val (delay) = argList + val (maxDelayAfterWindowReady) = argList when { - delay.isJsNullish() -> scriptRuntime.floaty.getClip() - else -> scriptRuntime.floaty.getClip(coerceLongNumber(delay!!, 0L)) + maxDelayAfterWindowReady.isJsNullish() -> scriptRuntime.floaty.getClip() + else -> scriptRuntime.floaty.getClip(coerceLongNumber(maxDelayAfterWindowReady!!, 0L)) } } @@ -133,7 +133,7 @@ class Floaty(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) { } } - private fun toXMLString(xml: Any) = when (xml) { + fun toXMLString(xml: Any): String = when (xml) { is XML -> xml.toXMLString() else -> xml.toString() } diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/global/Global.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/global/Global.kt index e54a4e2f..d713c09e 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/global/Global.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/global/Global.kt @@ -1,5 +1,6 @@ package org.autojs.autojs.runtime.api.augment.global +import android.os.Build import io.github.g00fy2.versioncompare.Version import org.autojs.autojs.annotation.RhinoFunctionBody import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface @@ -295,7 +296,14 @@ class Global(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti @JvmStatic @RhinoRuntimeFunctionInterface fun getClip(scriptRuntime: ScriptRuntime, args: Array): String = ensureArgumentsIsEmpty(args) { - scriptRuntime.clip + val legacyResult = scriptRuntime.clip + when { + legacyResult.isNotEmpty() -> legacyResult + Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && scriptRuntime.floaty.hasPermission() -> { + scriptRuntime.floaty.getClip() + } + else -> legacyResult + } } @JvmStatic diff --git a/version.properties b/version.properties index 7d43ad88..d31c160a 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ -#Sat Apr 12 12:49:14 CST 2025 -BUILD_TIME=1744433354412 +#Sat Apr 12 21:14:15 CST 2025 +BUILD_TIME=1744463655564 COMPILE_SDK_VERSION=35 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=35 TARGET_SDK_VERSION_INRT=29 -VERSION_BUILD=3128 +VERSION_BUILD=3130 VERSION_NAME=6.6.2 Alpha6 VSCODE_EXT_REQUIRED_VERSION=1.0.8