diff --git a/app/src/main/java/li/songe/gkd/data/Rule.kt b/app/src/main/java/li/songe/gkd/data/Rule.kt index bf3904f24..f4fa99d05 100644 --- a/app/src/main/java/li/songe/gkd/data/Rule.kt +++ b/app/src/main/java/li/songe/gkd/data/Rule.kt @@ -83,11 +83,7 @@ data class Rule( return activityIds.any { activityId.startsWith(it) } } - val performAction: ActionFc = when (rule.action) { - "clickNode" -> clickNode - "clickCenter" -> clickCenter - else -> click - } + val performAction = getActionFc(rule.action) companion object { const val defaultMiniCd = 1000L @@ -98,7 +94,7 @@ typealias ActionFc = (context: AccessibilityService, node: AccessibilityNodeInfo @Serializable -data class ClickAction( +data class GkdAction( val selector: String, val quickFind: Boolean = false, val action: String? = null, @@ -144,4 +140,20 @@ val clickCenter: ActionFc = { context, node -> } ) +} + +val backFc: ActionFc = { context, _ -> + ActionResult( + action = "back", + result = context.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK) + ) +} + +fun getActionFc(action: String?): ActionFc { + return when (action) { + "clickNode" -> clickNode + "clickCenter" -> clickCenter + "back" -> backFc + else -> click + } } \ No newline at end of file diff --git a/app/src/main/java/li/songe/gkd/debug/HttpService.kt b/app/src/main/java/li/songe/gkd/debug/HttpService.kt index e015e2e54..0eedd451e 100644 --- a/app/src/main/java/li/songe/gkd/debug/HttpService.kt +++ b/app/src/main/java/li/songe/gkd/debug/HttpService.kt @@ -31,7 +31,7 @@ import kotlinx.serialization.Serializable import li.songe.gkd.app import li.songe.gkd.appScope import li.songe.gkd.composition.CompositionService -import li.songe.gkd.data.ClickAction +import li.songe.gkd.data.GkdAction import li.songe.gkd.data.DeviceInfo import li.songe.gkd.data.RpcError import li.songe.gkd.data.SubsItem @@ -120,9 +120,9 @@ class HttpService : CompositionService({ if (!GkdAbService.isRunning()) { throw RpcError("无障碍没有运行") } - val clickAction = call.receive() - LogUtils.d(clickAction) - call.respond(GkdAbService.execClickAction(clickAction)) + val gkdAction = call.receive() + LogUtils.d(gkdAction) + call.respond(GkdAbService.execAction(gkdAction)) } } } diff --git a/app/src/main/java/li/songe/gkd/service/GkdAbService.kt b/app/src/main/java/li/songe/gkd/service/GkdAbService.kt index 32b975c29..e60be843e 100644 --- a/app/src/main/java/li/songe/gkd/service/GkdAbService.kt +++ b/app/src/main/java/li/songe/gkd/service/GkdAbService.kt @@ -29,14 +29,12 @@ import li.songe.gkd.composition.CompositionAbService import li.songe.gkd.composition.CompositionExt.useLifeCycleLog import li.songe.gkd.composition.CompositionExt.useScope import li.songe.gkd.data.ActionResult -import li.songe.gkd.data.ClickAction import li.songe.gkd.data.ClickLog +import li.songe.gkd.data.GkdAction import li.songe.gkd.data.NodeInfo import li.songe.gkd.data.RpcError import li.songe.gkd.data.SubscriptionRaw -import li.songe.gkd.data.click -import li.songe.gkd.data.clickCenter -import li.songe.gkd.data.clickNode +import li.songe.gkd.data.getActionFc import li.songe.gkd.db.DbSet import li.songe.gkd.shizuku.useSafeGetTasksFc import li.songe.gkd.util.Singleton @@ -123,7 +121,8 @@ class GkdAbService : CompositionAbService({ ) } else { topActivityFlow.value = topActivityFlow.value?.copy( - appId = rightAppId, activityId = shizukuActivityId, + appId = rightAppId, + activityId = shizukuActivityId, sourceId = newActivityId ) } @@ -311,23 +310,19 @@ class GkdAbService : CompositionAbService({ var service: GkdAbService? = null fun isRunning() = ServiceUtils.isServiceRunning(GkdAbService::class.java) - fun execClickAction(clickAction: ClickAction): ActionResult { + fun execAction(gkdAction: GkdAction): ActionResult { val serviceVal = service ?: throw RpcError("无障碍没有运行") val selector = try { - Selector.parse(clickAction.selector) + Selector.parse(gkdAction.selector) } catch (e: Exception) { throw RpcError("非法选择器") } val targetNode = - serviceVal.safeActiveWindow?.querySelector(selector, clickAction.quickFind) + serviceVal.safeActiveWindow?.querySelector(selector, gkdAction.quickFind) ?: throw RpcError("没有选择到节点") - return when (clickAction.action) { - "clickNode" -> clickNode(serviceVal, targetNode) - "clickCenter" -> clickCenter(serviceVal, targetNode) - else -> click(serviceVal, targetNode) - } + return getActionFc(gkdAction.action)(serviceVal, targetNode) } diff --git a/app/src/main/java/li/songe/gkd/ui/SnapshotPage.kt b/app/src/main/java/li/songe/gkd/ui/SnapshotPage.kt index bde323bcf..a823342be 100644 --- a/app/src/main/java/li/songe/gkd/ui/SnapshotPage.kt +++ b/app/src/main/java/li/songe/gkd/ui/SnapshotPage.kt @@ -204,15 +204,35 @@ fun SnapshotPage() { ) Divider() if (recordStore.snapshotIdMap.containsKey(snapshotVal.id)) { + val url = + "https://i.gkd.li/import/" + recordStore.snapshotIdMap[snapshotVal.id] Text( text = "复制链接", modifier = Modifier .clickable(onClick = { selectedSnapshot = null - ClipboardUtils.copyText("https://gkd-kit.gitee.io/import/" + recordStore.snapshotIdMap[snapshotVal.id]) + ClipboardUtils.copyText(url) ToastUtils.showShort("复制成功") }) .then(modifier) ) + Divider() + Text( + text = "分享链接", modifier = Modifier + .clickable(onClick = { + selectedSnapshot = null + val intent = Intent().apply { + action = Intent.ACTION_SEND + putExtra(Intent.EXTRA_TEXT, url) + type = "text/plain" + } + context.startActivity( + Intent.createChooser( + intent, "分享链接" + ) + ) + }) + .then(modifier) + ) } else { Text( text = "生成链接(需科学上网)", modifier = Modifier