| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- @echo off
- chcp 65001 >nul
- setlocal enabledelayedexpansion
- echo ========================================
- echo Switch to Sogou Input Method
- 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 adb-path-config.js using PowerShell
- echo [0/5] Reading ADB path from adb-path-config.js...
- for /f "delims=" %%i in ('powershell -Command "$content = Get-Content '%PROJECT_ROOT%\adb-path-config.js' -Raw; if ($content -match '\"adb-path\"\s*:\s*''([^'']+)''') { $adbPath = $matches[1]; $fullPath = $adbPath.TrimEnd([char]92) + [char]92 + 'adb.exe'; if (Test-Path $fullPath) { Write-Output $fullPath } else { Write-Output 'adb' } } else { Write-Output 'adb' }"') do set "ADB_PATH=%%i"
- if "%ADB_PATH%"=="" set "ADB_PATH=adb"
- echo Using ADB: %ADB_PATH%
- echo.
- REM Set fixed device address
- set "DEVICE_ADDRESS=192.168.2.5:5555"
- set "USE_DEVICE_OPTION=-s !DEVICE_ADDRESS!"
- echo Using device: !DEVICE_ADDRESS!
- echo.
- echo [1/5] Check if ADB is available...
- "%ADB_PATH%" version >nul 2>&1
- if errorlevel 1 (
- echo Error: ADB not found at: %ADB_PATH%
- echo Please check adb-path-config.js and ensure ADB path is correct
- pause
- exit /b 1
- )
- echo ADB is available
- echo.
- echo [2/5] Check connected devices...
- echo.
- "%ADB_PATH%" devices
- echo.
- REM Try to connect if not already connected
- echo Checking if device !DEVICE_ADDRESS! is connected...
- "%ADB_PATH%" !USE_DEVICE_OPTION! get-state >nul 2>&1
- if errorlevel 1 (
- echo Device not connected, attempting to connect...
- "%ADB_PATH%" connect !DEVICE_ADDRESS! >nul 2>&1
- timeout /t 2 /nobreak >nul
- "%ADB_PATH%" !USE_DEVICE_OPTION! get-state >nul 2>&1
- if errorlevel 1 (
- echo Error: Cannot connect to device !DEVICE_ADDRESS!
- echo.
- echo Please ensure:
- echo 1. Device is on the same network
- echo 2. Run 0-TEST-CONNECT.BAT to test connection first
- pause
- exit /b 1
- )
- echo Device connected successfully
- ) else (
- echo Device already connected
- )
- echo.
- echo.
- echo [3/5] Check current default input method...
- echo.
- for /f "delims=" %%i in ('"%ADB_PATH%" !USE_DEVICE_OPTION! shell settings get secure default_input_method') do set "CURRENT_IME=%%i"
- set "CURRENT_IME=!CURRENT_IME: =!"
- echo Current default IME: !CURRENT_IME!
- echo.
- REM Target input method: Sogou Input Method
- set "TARGET_IME=com.sohu.inputmethod.sogou/.SogouIME"
- REM Check if already using target input method
- if "!CURRENT_IME!"=="!TARGET_IME!" (
- echo Sogou Input Method is already the default input method.
- echo No action needed.
- pause
- exit /b 0
- )
- echo [4/5] List available input methods...
- echo.
- "%ADB_PATH%" !USE_DEVICE_OPTION! shell ime list -s
- echo.
- echo [5/5] Switch to Sogou Input Method...
- echo Setting !TARGET_IME! as default input method...
- "%ADB_PATH%" !USE_DEVICE_OPTION! shell ime enable !TARGET_IME!
- if errorlevel 1 (
- echo Warning: Failed to enable Sogou Input Method
- echo Make sure Sogou Input Method is installed on your device
- echo.
- ) else (
- echo Sogou Input Method enabled successfully
- echo.
- )
- "%ADB_PATH%" !USE_DEVICE_OPTION! shell ime set !TARGET_IME!
- if errorlevel 1 (
- echo Error: Failed to set default input method
- pause
- exit /b 1
- )
- echo Default input method set successfully
- echo.
- echo Verifying current default input method...
- for /f "delims=" %%i in ('"%ADB_PATH%" !USE_DEVICE_OPTION! shell settings get secure default_input_method') do set "NEW_IME=%%i"
- set "NEW_IME=!NEW_IME: =!"
- echo Current default IME: !NEW_IME!
- echo.
- if "!NEW_IME!"=="!TARGET_IME!" (
- echo ========================================
- echo Success: Sogou Input Method is now default
- echo ========================================
- ) else (
- echo ========================================
- echo Warning: Failed to set Sogou Input Method as default
- echo Expected: !TARGET_IME!
- echo Current: !NEW_IME!
- echo ========================================
- )
- echo.
- pause
|