# Govori / Talk & Learn — установка приложения на смарт-часы (Wear OS) с компьютера на Windows. # Запуск (PowerShell): # [Net.ServicePointManager]::SecurityProtocol=3072; iex ([Text.Encoding]::UTF8.GetString((New-Object Net.WebClient).DownloadData('https://govori.site/smartwatch-install.ps1'))) # Язык сообщений — из системы; задать вручную: $env:GOVORI_LANG='en' (ru | en | es). # Инструкция: https://govori.site/smartwatch#install-computer # # Что делает: скачивает Android platform-tools (adb) с сайта Google и приложение для смарт-часов # с builds.govori.site во временную папку, сверяет контрольную сумму, затем # adb pair → adb connect → adb install → разрешение на самообновление → запуск приложения. # Ничего не ставит в систему; временная папка удаляется в конце. & { # Не Stop: в PowerShell 5.1 любой вывод adb в stderr тогда становится исключением. $ErrorActionPreference = 'Continue' $ProgressPreference = 'SilentlyContinue' # без полосы прогресса Invoke-WebRequest качает в разы быстрее [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $AppId = 'app.talkandlearn.messenger' $Builds = 'https://builds.govori.site/govori-builds/apks' $ApkUrl = "$Builds/latest-watch-prod.apk" $InfoUrl = "$Builds/update-info-watch-prod.json" # --- язык --------------------------------------------------------------------- $lang = $env:GOVORI_LANG if (-not $lang) { switch -Wildcard ((Get-UICulture).Name) { 'ru*' { $lang = 'ru' } 'es*' { $lang = 'es' } default { $lang = 'en' } } } function Pick($ru, $en, $es) { switch ($lang) { 'ru' { $ru } 'es' { $es } default { $en } } } function Say($ru, $en, $es) { Write-Host (Pick $ru $en $es) } function Ask($ru, $en, $es) { ((Read-Host (Pick $ru $en $es)) -replace '\s', '') } function Fail($ru, $en, $es) { Write-Host ((Pick 'Ошибка: ' 'Error: ' 'Error: ') + (Pick $ru $en $es)) -ForegroundColor Red throw 'govori-watch-install' } $work = Join-Path $env:TEMP ('govori-watch-' + [guid]::NewGuid().ToString('N').Substring(0, 8)) New-Item -ItemType Directory -Path $work -ErrorAction Stop | Out-Null $adb = $null $ownAdb = $false # adb скачан этим скриптом — тогда в конце гасим его сервер, иначе папку не удалить try { Write-Host '' Say '== Установка «Говори!» на смарт-часы ==' '== Installing Talk & Learn on a smartwatch ==' '== Instalación de Talk & Learn en el reloj inteligente ==' Say 'Смарт-часы и этот компьютер должны быть в одной домашней сети (Wi-Fi).' ` 'The smartwatch and this computer must be on the same home Wi-Fi.' ` 'El reloj y este ordenador deben estar en la misma red wifi de casa.' Write-Host '' # --- 1. adb ------------------------------------------------------------------- $existing = Get-Command adb -ErrorAction SilentlyContinue # Свой adb подходит, только если умеет «pair» (platform-tools 30+), иначе берём свежий. if ($existing -and ((& $existing.Source help 2>&1 | Out-String) -match 'pair')) { $adb = $existing.Source } else { Say '1/5 Скачиваю инструменты Android (platform-tools) с сайта Google…' ` '1/5 Downloading Android platform-tools from Google…' ` '1/5 Descargando Android platform-tools de Google…' try { Invoke-WebRequest -UseBasicParsing -Uri 'https://dl.google.com/android/repository/platform-tools-latest-windows.zip' -OutFile "$work\pt.zip" -ErrorAction Stop } catch { Fail 'не удалось скачать platform-tools' 'could not download platform-tools' 'no se pudo descargar platform-tools' } Expand-Archive -Path "$work\pt.zip" -DestinationPath $work -Force -ErrorAction Stop $adb = "$work\platform-tools\adb.exe" $ownAdb = $true } # --- 2. приложение для смарт-часов ------------------------------------------------ Say '2/5 Скачиваю приложение для смарт-часов…' '2/5 Downloading the smartwatch app…' '2/5 Descargando la app para el reloj…' try { Invoke-WebRequest -UseBasicParsing -Uri $ApkUrl -OutFile "$work\watch.apk" -ErrorAction Stop } catch { Fail 'не удалось скачать приложение' 'could not download the app' 'no se pudo descargar la app' } $expected = $null try { $expected = (Invoke-RestMethod -UseBasicParsing -Uri $InfoUrl -ErrorAction Stop).sha256 } catch { } if ($expected) { $actual = (Get-FileHash -Algorithm SHA256 -Path "$work\watch.apk" -ErrorAction Stop).Hash.ToLower() # Файл latest и описание версии обновляются вместе; расхождение — значит, скачалось не то. if ($actual -ne $expected.ToLower()) { Fail 'файл повреждён, запустите ещё раз' 'the file is damaged, run again' 'el archivo está dañado, vuelve a ejecutar' } } & $adb start-server 2>&1 | Out-Null # --- 3. сопряжение ---------------------------------------------------------------- Write-Host '' Say '3/5 Сопряжение. На смарт-часах: Настройки → Параметры разработчика → «Отладка по беспроводной сети» →' ` '3/5 Pairing. On the smartwatch: Settings → Developer options → Wireless debugging →' ` '3/5 Vinculación. En el reloj: Ajustes → Opciones de desarrollador → Depuración inalámbrica →' Say ' «Подключить новое устройство». На экране — адрес (IP-адрес и порт) и код из 6 цифр.' ` ' Pair new device. The screen shows an address (IP address and port) and a 6-digit code.' ` ' Vincular nuevo dispositivo. En la pantalla aparecen una dirección (IP y puerto) y un código de 6 dígitos.' $paired = $false foreach ($attempt in 1..3) { $pairAddr = Ask 'Адрес с экрана смарт-часов (например 192.168.0.56:37123)' ` 'Address from the smartwatch screen (e.g. 192.168.0.56:37123)' ` 'Dirección de la pantalla del reloj (p. ej. 192.168.0.56:37123)' $pairCode = Ask 'Код из 6 цифр' '6-digit code' 'Código de 6 dígitos' $out = (& $adb pair $pairAddr $pairCode 2>&1 | Out-String) Write-Host $out if ($out -match '(?i)success') { $paired = $true; break } Say 'Не получилось. Проверьте адрес и код (код меняется, если экран смарт-часов закрылся).' ` "Didn't work. Check the address and code (the code changes if the smartwatch screen was closed)." ` 'No funcionó. Revisa la dirección y el código (cambia si se cerró la pantalla del reloj).' } if (-not $paired) { Fail 'сопряжение не удалось' 'pairing failed' 'la vinculación falló' } $watchIp = $pairAddr.Substring(0, $pairAddr.LastIndexOf(':')) # «Successfully paired to … [guid=adb-XXXX-yyyy]»: под этим именем adb сам подключает смарт-часы # по сети («adb-XXXX-yyyy._adb-tls-connect._tcp»), не по IP. $watchGuid = $null if ($out -match 'guid=([^\]\s]+)') { $watchGuid = $Matches[1] } # --- 4. подключение ----------------------------------------------------------------- Write-Host '' Say '4/5 Подключение…' '4/5 Connecting…' '4/5 Conectando…' function Find-Device($prefix) { foreach ($line in (& $adb devices 2>&1)) { $parts = ("$line" -split '\s+') if ($parts.Count -ge 2 -and $parts[1] -eq 'device' -and $parts[0].StartsWith($prefix)) { return $parts[0] } } return $null } $device = $null # После сопряжения adb часто находит смарт-часы сам (по сети); ждём несколько секунд. foreach ($i in 1..10) { $device = Find-Device "${watchIp}:" if (-not $device -and $watchGuid) { $device = Find-Device $watchGuid } if ($device) { break } foreach ($line in (& $adb mdns services 2>&1)) { if ("$line" -match '_adb-tls-connect' -and "$line" -match ([regex]::Escape($watchIp) + ':\d+')) { & $adb connect $Matches[0] 2>&1 | Out-Null } } Start-Sleep -Seconds 1 } while (-not $device) { Say 'На смарт-часах закройте окно с кодом. Вверху экрана «Отладка по беспроводной сети» — адрес и порт' ` 'On the smartwatch, close the code window. The Wireless debugging screen shows an address and port' ` 'En el reloj, cierra la ventana del código. La pantalla de Depuración inalámbrica muestra una dirección y un puerto' Say '(порт другой, не тот, что был с кодом).' '(a different port from the one with the code).' '(otro puerto, no el del código).' $connAddr = Ask 'Адрес и порт' 'Address and port' 'Dirección y puerto' if ($connAddr -notmatch ':') { $connAddr = "${watchIp}:$connAddr" } & $adb connect $connAddr 2>&1 | Write-Host $device = Find-Device $connAddr } # --- 5. установка ------------------------------------------------------------------- Say '5/5 Устанавливаю приложение (до минуты)…' '5/5 Installing the app (up to a minute)…' '5/5 Instalando la app (hasta un minuto)…' $out = (& $adb -s $device install -r "$work\watch.apk" 2>&1 | Out-String) Write-Host $out if ($out -notmatch '(?i)success') { Fail 'установка не удалась' 'install failed' 'la instalación falló' } # Разрешение «установка приложений» — без него смарт-часы не смогут обновлять приложение сами. & $adb -s $device shell appops set $AppId REQUEST_INSTALL_PACKAGES allow 2>&1 | Out-Null & $adb -s $device shell monkey -p $AppId -c android.intent.category.LAUNCHER 1 2>&1 | Out-Null & $adb disconnect $device 2>&1 | Out-Null Write-Host '' Say 'Готово! «Говори!» открылся на смарт-часах.' 'Done! Talk & Learn is open on the smartwatch.' '¡Listo! Talk & Learn está abierto en el reloj.' Say 'Дальше:' 'Next:' 'Ahora:' Say ' 1. Вход: наведите камеру телефона на QR-код на смарт-часах — или в «Говори!» на телефоне' ` ' 1. Sign in: point the phone camera at the QR code on the smartwatch — or in Talk & Learn on the phone' ` ' 1. Inicio de sesión: apunta la cámara del teléfono al código QR del reloj, o en Talk & Learn del teléfono' Say ' Настройки → Смарт-часы → «Подключить смарт-часы» и введите код с экрана смарт-часов.' ` ' open Settings → Smartwatch → Connect smartwatch and enter the code from the smartwatch screen.' ` ' abre Ajustes → Reloj inteligente → Conectar reloj inteligente e introduce el código del reloj.' Say ' Или здесь, на компьютере: https://app.govori.site/watch — войдите в аккаунт и введите код.' ` ' Or right here on the computer: https://app.govori.site/watch — sign in and enter the code.' ` ' O aquí, en el ordenador: https://app.govori.site/watch — inicia sesión e introduce el código.' Say ' 2. На смарт-часах выключите «Отладку по беспроводной сети» и «Отладку ADB».' ` ' 2. On the smartwatch, turn off Wireless debugging and ADB debugging.' ` ' 2. En el reloj, desactiva Depuración inalámbrica y Depuración ADB.' } catch { if ("$_" -ne 'govori-watch-install') { Write-Host ("$_") -ForegroundColor Red } } finally { if ($ownAdb) { & $adb kill-server 2>&1 | Out-Null; Start-Sleep -Milliseconds 500 } Remove-Item -Recurse -Force $work -ErrorAction SilentlyContinue } }