| 1234567891011121314151617181920 |
- /**
- * adb method: press — 按图点击(匹配图片位置后点击)
- */
- async function run(action, ctx) {
- const { device, folderPath, variableContext, api, extractVarName } = ctx
- const inVars = action.inVars || []
- const imagePath = inVars.length > 0 ? (variableContext[extractVarName(inVars[0])] || inVars[0]) : action.value
- if (!imagePath) return { success: false, error: 'press 操作缺少图片路径' }
- const fullPath = imagePath.startsWith('/') || imagePath.includes(':') ? imagePath : `${folderPath}/${imagePath}`
- if (!api?.matchImageAndGetCoordinate) return { success: false, error: '图像匹配 API 不可用' }
- const matchResult = await api.matchImageAndGetCoordinate(device, fullPath, folderPath)
- 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 }
|