adb-disconnect.js 752 B

1234567891011121314151617181920212223
  1. #!/usr/bin/env node
  2. const { execSync } = require('child_process')
  3. const path = require('path')
  4. // 从配置文件读取 ADB 路径
  5. const config = require(path.join(__dirname, '..', '..', 'configs', 'config.js'))
  6. const projectRoot = path.resolve(__dirname, '..', '..')
  7. const adbPath = config.adbPath?.path
  8. ? path.resolve(projectRoot, config.adbPath.path)
  9. : path.join(projectRoot, 'lib', 'scrcpy-adb', 'adb.exe')
  10. const deviceIp = process.argv[2]
  11. const devicePort = process.argv[3] || '5555'
  12. if (!deviceIp) {
  13. process.exit(1)
  14. }
  15. const deviceId = `${deviceIp}:${devicePort}`
  16. const disconnectCommand = `"${adbPath}" disconnect ${deviceId}`
  17. const disconnectOutput = execSync(disconnectCommand, { encoding: 'utf-8', timeout: 500 })
  18. process.exit(0)