| 12345678910111213141516171819202122 |
- $ErrorActionPreference = 'SilentlyContinue'
- $TCPIP_PORT = 5555
- $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
- $root = (Get-Item (Join-Path $scriptDir '..\..')).FullName
- $adb = Join-Path $root 'lib\scrcpy-adb\adb.exe'
- if (-not (Test-Path $adb)) { Write-Host '[ERROR] ADB not found'; exit 1 }
- $lines = & $adb devices 2>$null
- $devices = $lines | ForEach-Object { $t = $_.Trim(); if ($t -match '^(\S+)\s+device') { $Matches[1] } } | Where-Object { $_ }
- $dev = $devices | Select-Object -First 1
- if (-not $dev) { Write-Host 'No devices found. Please connect a device via USB.'; exit 1 }
- if ($devices.Count -gt 1) { Write-Host "Multiple devices. Using: $dev" }
- & $adb -s $dev shell 'settings put global adb_wifi_enabled 1' 2>$null | Out-Null
- $wireless = (& $adb -s $dev shell 'settings get global adb_wifi_enabled' 2>$null).Trim()
- if ($wireless -eq '1') { Write-Host 'Wireless debugging enabled.' } else { Write-Host 'Wireless setting may not be supported. Enable it in Settings > Developer options.' }
- $wlanIp = (& $adb -s $dev shell 'getprop dhcp.wlan0.ipaddress' 2>$null).Trim()
- if ($wlanIp -notmatch '^\d+\.\d+\.\d+\.\d+$') {
- $out = & $adb -s $dev shell 'ip -4 addr show wlan0' 2>$null
- if ($out -match 'inet\s+(\d+\.\d+\.\d+\.\d+)') { $wlanIp = $Matches[1] }
- }
- $tcpipOut = & $adb -s $dev tcpip $TCPIP_PORT 2>$null
- Write-Host $tcpipOut
- if ($wlanIp) { Write-Host "Wireless: adb connect ${wlanIp}:${TCPIP_PORT}" }
|