| 1234567891011121314151617181920212223 |
- /** 语句:string-press 文字识别并点击 */
- const types = ['string-press']
- function parse(action, parseContext) {
- return Object.assign({}, action, { type: 'string-press' })
- }
- async function execute(action, ctx) {
- const { device, api, resolveValue, variableContext } = ctx
- const inVars = action.inVars || []
- let targetText = inVars.length > 0 ? (variableContext[ctx.extractVarName(inVars[0])] || action.value) : (resolveValue(action.value, variableContext) || 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}` }
- 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}` }
- return { success: true }
- }
- module.exports = { types, parse, execute }
|