| 12345678910111213141516171819 |
- /**
- * adb method: string-press — 按文字点击(OCR 匹配文字后点击)
- */
- async function run(action, ctx) {
- const { device, variableContext, api, extractVarName } = ctx
- const inVars = action.inVars || []
- const targetText = inVars.length > 0 ? (variableContext[extractVarName(inVars[0])] || inVars[0]) : action.value
- if (!targetText) return { success: false, error: 'string-press 操作缺少文字内容' }
- if (!api?.findTextAndGetCoordinate) return { success: false, error: '文字识别 API 不可用' }
- const matchResult = await api.findTextAndGetCoordinate(device, targetText)
- if (!matchResult.success) return { success: false, error: `文字识别失败: ${matchResult.error != null ? matchResult.error : 'unknown'}` }
- const { x, y } = matchResult.clickPosition
- if (!api?.sendTap) return { success: false, error: '点击 API 不可用' }
- const tapResult = await api.sendTap(device, x, y)
- if (!tapResult.success) return { success: false, error: `点击失败: ${tapResult.error != null ? tapResult.error : 'unknown'}` }
- return { success: true }
- }
- module.exports = { run }
|