swipe-parser.js 655 B

1234567891011121314151617
  1. /** 语句:swipe 滑动 */
  2. const types = ['swipe']
  3. function parse(action, parseContext) {
  4. return Object.assign({}, action, { type: 'swipe' })
  5. }
  6. async function execute(action, ctx) {
  7. const { device, resolution, api, calculateSwipeCoordinates } = ctx
  8. if (!api.sendSwipe) return { success: false, error: '滑动 API 不可用' }
  9. const { x1, y1, x2, y2 } = calculateSwipeCoordinates(action.value, resolution.width, resolution.height)
  10. const r = await api.sendSwipe(device, x1, y1, x2, y2, 300)
  11. if (!r.success) return { success: false, error: `滑动失败: ${r.error}` }
  12. return { success: true }
  13. }
  14. module.exports = { types, parse, execute }