@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

echo ========================================
echo Enable ADB TCP/IP Mode (Port 5555)
echo ========================================
echo.

REM Get the directory where this batch file is located
set "SCRIPT_DIR=%~dp0"
set "PROJECT_ROOT=%SCRIPT_DIR%.."

REM Read ADB path from config.js using PowerShell
echo [0/2] Reading ADB path from config.js...
for /f "delims=" %%i in ('powershell -Command "$content = Get-Content '%PROJECT_ROOT%\config.js' -Raw; $content = $content -replace 'module\.exports\s*=\s*', ''; $content = $content -replace ';', ''; $content = $content.Trim(); $json = $content | ConvertFrom-Json; $adbPath = $json.'adb-path'; if ($adbPath) { Write-Output ($adbPath.TrimEnd('\') + '\adb.exe') } else { Write-Output 'adb' }"') do set "ADB_PATH=%%i"

if "%ADB_PATH%"=="" set "ADB_PATH=adb"
echo Using ADB: %ADB_PATH%
echo.

echo [1/2] List connected devices...
"%ADB_PATH%" devices
echo.

echo [2/2] Enable TCP/IP mode...
"%ADB_PATH%" tcpip 5555
echo.

echo ========================================
echo Done
echo ========================================
echo.
pause
