| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #!/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 deviceIp = process.argv[2]
- const devicePort = process.argv[3] || '5555'
- if (!deviceIp) {
- process.exit(1)
- }
- const disconnectCommand = `"${adbPath}" disconnect ${deviceIp}:${devicePort}`
- try {
- execSync(disconnectCommand, { encoding: 'utf-8', stdio: 'ignore', timeout: 100 })
- } catch (error) {
- // Ignore errors on disconnect, as device might not be connected
- }
- const connectCommand = `"${adbPath}" connect ${deviceIp}:${devicePort}`
- let connectSuccess = false
- try {
- const connectOutput = execSync(connectCommand, { encoding: 'utf-8', timeout: 500 })
- connectSuccess = connectOutput.trim().includes('connected') || connectOutput.trim().includes('already connected')
- } catch (error) {
- // Connection failed, execSync might throw if timeout or command fails
- }
- if (!connectSuccess) {
- process.exit(1)
- }
- // Verify device is actually available in device list
- let isDeviceAvailable = false
- try {
- const devicesCommand = `"${adbPath}" devices`
- const devicesOutput = execSync(devicesCommand, { encoding: 'utf-8' })
- const deviceAddress = `${deviceIp}:${devicePort}`
- isDeviceAvailable = devicesOutput.includes(deviceAddress) && devicesOutput.includes('device')
- } catch (error) {
- // Error checking devices
- }
- if (isDeviceAvailable) {
- process.exit(0)
- } else {
- process.exit(1)
- }
|