/** * adb method: swipe — 滑动(方向或起止坐标) */ const { calculateSwipeCoordinates } = require('./utils.js') async function run(action, ctx) { const { device, resolution, variableContext, api, extractVarName, resolveValue } = ctx const inVars = action.inVars || [] let direction = inVars.length > 0 ? (variableContext[extractVarName(inVars[0])] || inVars[0]) : resolveValue(action.value, variableContext) if (!direction) return { success: false, error: 'swipe 操作缺少方向参数' } let x1, y1, x2, y2 if (inVars.length >= 3) { const start = variableContext[extractVarName(inVars[1])] const end = variableContext[extractVarName(inVars[2])] if (start && end) { x1 = start.x ?? start[0] y1 = start.y ?? start[1] x2 = end.x ?? end[0] y2 = end.y ?? end[1] } } if (x1 === undefined || y1 === undefined || x2 === undefined || y2 === undefined) { const coords = calculateSwipeCoordinates(direction, resolution.width, resolution.height) x1 = coords.x1 y1 = coords.y1 x2 = coords.x2 y2 = coords.y2 } if (!api?.sendSwipe) return { success: false, error: '滑动 API 不可用' } const swipeResult = await api.sendSwipe(device, x1, y1, x2, y2, 300) if (!swipeResult.success) return { success: false, error: `滑动失败: ${swipeResult.error != null ? swipeResult.error : 'unknown'}` } return { success: true } } module.exports = { run }