From c6eaa2ecb23414230ec408a3d558d9bdd6ebc65d Mon Sep 17 00:00:00 2001 From: gallonyin Date: Mon, 3 Jul 2023 18:36:12 +0800 Subject: [PATCH] =?UTF-8?q?update=20app=E5=A4=96=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E7=A6=81=E6=AD=A2=E8=87=AA=E5=8A=A8=E8=B7=B3=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 +- .../yameida/worktool/service/GlobalMethod.kt | 25 ++++++----- .../worktool/service/WeworkOperationImpl.kt | 42 +++++++++++++++---- .../worktool/utils/AccessibilityUtil.kt | 16 +++---- 4 files changed, 57 insertions(+), 30 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b5bd951..a0260f4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.yameida.worktool" minSdkVersion 24 targetSdkVersion 30 - versionCode 26041 - versionName "2.6.4" + versionCode 26042 + versionName "2.6.4.2" } buildTypes { diff --git a/app/src/main/java/org/yameida/worktool/service/GlobalMethod.kt b/app/src/main/java/org/yameida/worktool/service/GlobalMethod.kt index 459fde7..669269e 100644 --- a/app/src/main/java/org/yameida/worktool/service/GlobalMethod.kt +++ b/app/src/main/java/org/yameida/worktool/service/GlobalMethod.kt @@ -112,7 +112,7 @@ fun getRoot(): AccessibilityNodeInfo { * 获取前台窗口 * @param ignoreCheck false 必须等待前台为企业微信 true 直接返回当前前台窗口 */ -fun getRoot(ignoreCheck: Boolean): AccessibilityNodeInfo { +fun getRoot(ignoreCheck: Boolean, share: Boolean = false): AccessibilityNodeInfo { while (true) { val tempRoot = WeworkController.weworkService.rootInActiveWindow val root = WeworkController.weworkService.rootInActiveWindow @@ -139,16 +139,19 @@ fun getRoot(ignoreCheck: Boolean): AccessibilityNodeInfo { error("点击关闭应用ANR") } } - WeworkController.weworkService.currentPackage = root.packageName?.toString() ?: "" - if (System.currentTimeMillis() % 30 == 0L) { - error("当前不在企业微信: ${root.packageName}") - if (!FloatWindowHelper.isPause) { - ToastUtils.show("当前不在企业微信: ${root.packageName}\n尝试跳转到企业微信") - Utils.getApp().packageManager.getLaunchIntentForPackage(Constant.PACKAGE_NAMES) - ?.apply { - this.flags = Intent.FLAG_ACTIVITY_NEW_TASK - Utils.getApp().startActivity(this) - } + //app外场景禁止自动跳回(分享文件) + if (!share) { + WeworkController.weworkService.currentPackage = root.packageName?.toString() ?: "" + if (System.currentTimeMillis() % 30 == 0L) { + error("当前不在企业微信: ${root.packageName}") + if (!FloatWindowHelper.isPause) { + ToastUtils.show("当前不在企业微信: ${root.packageName}\n尝试跳转到企业微信") + Utils.getApp().packageManager.getLaunchIntentForPackage(Constant.PACKAGE_NAMES) + ?.apply { + this.flags = Intent.FLAG_ACTIVITY_NEW_TASK + Utils.getApp().startActivity(this) + } + } } } if (ignoreCheck) { diff --git a/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt b/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt index dcc34cd..1da87d7 100644 --- a/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt +++ b/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt @@ -434,11 +434,19 @@ object WeworkOperationImpl { AccessibilityUtil.performClick(imageViewList[1]) val shareFileButton = AccessibilityUtil.findOneByDesc(getRoot(), "以原文件分享", "用其他应用打开") AccessibilityUtil.performClick(shareFileButton) - var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true), "发送给同事") + var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true, share = true), "发送给同事") sleep(Constant.POP_WINDOW_INTERVAL) + if (shareToWorkButton == null) { + LogUtils.e("未找到发送给同事: $objectName") + if (retryCount > 0) { + return pushMicroDiskImage(message, titleList, objectName, extraText, retryCount - 1) + } + uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "未找到发送给同事: $objectName", startTime, listOf(), titleList) + return false + } AccessibilityUtil.performClick(shareToWorkButton) sleep(Constant.POP_WINDOW_INTERVAL) - shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true), "发送给同事") + shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage) val time = System.currentTimeMillis() var currentTime = time @@ -448,7 +456,7 @@ object WeworkOperationImpl { LogUtils.e("尝试手势点击!!!!!") AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton) sleep(Constant.CHANGE_PAGE_INTERVAL) - shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true), "发送给同事") + shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") } else { break } @@ -682,11 +690,19 @@ object WeworkOperationImpl { newFile.writeBytes(body.bytes()) LogUtils.i("文件存储本地成功 $filePath") ShareUtil.share("${if (fileType.isBlank()) "*" else fileType}/*", newFile) - var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true), "发送给同事") + var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true, share = true), "发送给同事") sleep(Constant.POP_WINDOW_INTERVAL) + if (shareToWorkButton == null) { + LogUtils.e("未找到发送给同事: $objectName") + if (retryCount > 0) { + return pushMicroDiskImage(message, titleList, objectName, extraText, retryCount - 1) + } + uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "未找到发送给同事: $objectName", startTime, listOf(), titleList) + return false + } AccessibilityUtil.performClick(shareToWorkButton) sleep(Constant.POP_WINDOW_INTERVAL) - shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true), "发送给同事") + shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage) val time = System.currentTimeMillis() var currentTime = time @@ -696,7 +712,7 @@ object WeworkOperationImpl { LogUtils.e("尝试手势点击!!!!!") AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton) sleep(Constant.CHANGE_PAGE_INTERVAL) - shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true), "发送给同事") + shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") } else { break } @@ -742,11 +758,19 @@ object WeworkOperationImpl { newFile.writeBytes(EncodeUtils.base64Decode(fileBase64)) LogUtils.i("文件存储本地成功 $filePath") ShareUtil.share("${if (fileType.isBlank()) "*" else fileType}/*", newFile) - var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true), "发送给同事") + var shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true, share = true), "发送给同事") sleep(Constant.POP_WINDOW_INTERVAL) + if (shareToWorkButton == null) { + LogUtils.e("未找到发送给同事: $objectName") + if (retryCount > 0) { + return pushMicroDiskImage(message, titleList, objectName, extraText, retryCount - 1) + } + uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "未找到发送给同事: $objectName", startTime, listOf(), titleList) + return false + } AccessibilityUtil.performClick(shareToWorkButton) sleep(Constant.POP_WINDOW_INTERVAL) - shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true), "发送给同事") + shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") LogUtils.v("尝试发送给同事", shareToWorkButton == null, WeworkController.weworkService.currentPackage) val time = System.currentTimeMillis() var currentTime = time @@ -756,7 +780,7 @@ object WeworkOperationImpl { LogUtils.e("尝试手势点击!!!!!") AccessibilityUtil.clickByNode(WeworkController.weworkService, shareToWorkButton) sleep(Constant.CHANGE_PAGE_INTERVAL) - shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true), "发送给同事") + shareToWorkButton = AccessibilityUtil.findOnceByText(getRoot(true, share = true), "发送给同事") } else { break } diff --git a/app/src/main/java/org/yameida/worktool/utils/AccessibilityUtil.kt b/app/src/main/java/org/yameida/worktool/utils/AccessibilityUtil.kt index 44f96d6..138b459 100644 --- a/app/src/main/java/org/yameida/worktool/utils/AccessibilityUtil.kt +++ b/app/src/main/java/org/yameida/worktool/utils/AccessibilityUtil.kt @@ -640,7 +640,7 @@ object AccessibilityUtil { if (result != null) return result sleep(SHORT_INTERVAL) if (root) { - node = getRoot(true) + node = getRoot(true, share = true) } else { node.refresh() } @@ -693,7 +693,7 @@ object AccessibilityUtil { if (result != null) return result sleep(SHORT_INTERVAL) if (root) { - node = getRoot(true) + node = getRoot(true, share = true) } else { node.refresh() } @@ -765,7 +765,7 @@ object AccessibilityUtil { if (result.size >= minSize) return result sleep(SHORT_INTERVAL) if (root) { - node = getRoot(true) + node = getRoot(true, share = true) } else { node.refresh() } @@ -830,7 +830,7 @@ object AccessibilityUtil { if (result.size >= minSize) return result sleep(SHORT_INTERVAL) if (root) { - node = getRoot(true) + node = getRoot(true, share = true) } else { node.refresh() } @@ -891,7 +891,7 @@ object AccessibilityUtil { if (result != null) return result sleep(SHORT_INTERVAL) if (root) { - node = getRoot(true) + node = getRoot(true, share = true) } else { node.refresh() } @@ -961,7 +961,7 @@ object AccessibilityUtil { if (result.size >= minSize) return result sleep(SHORT_INTERVAL) if (root) { - node = getRoot(true) + node = getRoot(true, share = true) } else { node.refresh() } @@ -1287,7 +1287,7 @@ object AccessibilityUtil { findOnceByText(node, *textList, exact = exact, desc = desc) ?: return true sleep(SHORT_INTERVAL) if (root) { - node = getRoot(true) + node = getRoot(true, share = true) } else { node.refresh() } @@ -1313,7 +1313,7 @@ object AccessibilityUtil { findOnceByClazz(node, *clazzList) ?: return true sleep(SHORT_INTERVAL) if (root) { - node = getRoot(true) + node = getRoot(true, share = true) } else { node.refresh() }