| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #!/usr/bin/env node
- const { execSync } = require('child_process')
- const path = require('path')
- const projectRoot = path.resolve(__dirname, '..', '..')
- const adbPath = path.join(projectRoot, 'exe', 'adb', 'adb.exe')
- const action = process.argv[2]
- if (!action) {
- process.exit(1)
- }
- switch (action) {
- case 'tap': {
- const coordX = process.argv[3]
- const coordY = process.argv[4]
- const deviceId = process.argv[5] || ''
-
- if (!coordX || !coordY) {
- process.exit(1)
- }
-
- const deviceFlag = deviceId && deviceId.includes(':') ? `-s ${deviceId} ` : ''
- const tapCommand = `"${adbPath}" ${deviceFlag}shell input tap ${coordX} ${coordY}`
- execSync(tapCommand, { encoding: 'utf-8', timeout: 1000 })
- process.exit(0)
- }
-
- case 'swipe': {
- const direction = process.argv[3]
- const distance = parseInt(process.argv[4])
- const duration = parseInt(process.argv[5])
- const deviceId = process.argv[6] || ''
-
- if (!direction || !distance || !duration) {
- process.exit(1)
- }
-
- const deviceFlag = deviceId && deviceId.includes(':') ? `-s ${deviceId} ` : ''
- const sizeCommand = `"${adbPath}" ${deviceFlag}shell wm size`
- const sizeOutput = execSync(sizeCommand, { encoding: 'utf-8', timeout: 1000 })
- const sizeMatch = sizeOutput.match(/(\d+)x(\d+)/)
-
- if (!sizeMatch) {
- process.exit(1)
- }
-
- const screenWidth = parseInt(sizeMatch[1])
- const screenHeight = parseInt(sizeMatch[2])
- const centerX = Math.floor(screenWidth / 2)
- const centerY = Math.floor(screenHeight / 2)
-
- let startX = centerX
- let startY = centerY
- let endX = centerX
- let endY = centerY
-
- switch (direction) {
- case 'up-down':
- startY = centerY - Math.floor(distance / 2)
- endY = centerY + Math.floor(distance / 2)
- break
- case 'down-up':
- startY = centerY + Math.floor(distance / 2)
- endY = centerY - Math.floor(distance / 2)
- break
- case 'left-right':
- startX = centerX - Math.floor(distance / 2)
- endX = centerX + Math.floor(distance / 2)
- break
- case 'right-left':
- startX = centerX + Math.floor(distance / 2)
- endX = centerX - Math.floor(distance / 2)
- break
- default:
- process.exit(1)
- }
-
- const swipeCommand = `"${adbPath}" ${deviceFlag}shell input swipe ${startX} ${startY} ${endX} ${endY} ${duration}`
- execSync(swipeCommand, { encoding: 'utf-8', timeout: 2000 })
- process.exit(0)
- }
-
- default:
- process.exit(1)
- }
|