| 12345678910111213141516171819202122232425262728 |
- #!/usr/bin/env node
- const { execSync } = require('child_process')
- const path = require('path')
- const fs = require('fs')
- // 根目录 = config 文件所在目录的上级(config 在 <根>/configs/config.js)
- const configPath = process.env.STATIC_ROOT
- ? path.join(path.dirname(process.env.STATIC_ROOT), 'configs', 'config.js')
- : path.join(__dirname, '..', '..', 'configs', 'config.js')
- const PROJECT_ROOT = path.dirname(path.dirname(path.resolve(configPath)))
- const config = fs.existsSync(configPath) ? require(configPath) : {}
- const adbPath = config.adbPath?.path
- ? (path.isAbsolute(config.adbPath.path) ? config.adbPath.path : path.resolve(PROJECT_ROOT, config.adbPath.path))
- : path.join(PROJECT_ROOT, 'lib', 'scrcpy-adb', process.platform === 'win32' ? 'adb.exe' : 'adb')
- const deviceIp = '192.168.0.101'
- const devicePort = '5555'
- /** Run adb connect and return whether connected. */
- function connect() {
- const out = execSync(`"${adbPath}" connect ${deviceIp}:${devicePort}`, { encoding: 'utf-8' }).trim()
- return out.includes('connected') || out.includes('already connected')
- }
- const ok = connect()
- console.log(ok ? `${deviceIp}:${devicePort} Connected` : `${deviceIp}:${devicePort} Connect failed`)
- process.exit(ok ? 0 : 1)
|