@echo off
setlocal
rem Flora cable install for Windows. Put this file next to the Flora APK and double-click it.
rem It installs Flora on a phone connected by USB cable. It contains no passwords or keys.
set PKG=online.seidrlabs.floravivo
set APK=%~dp0flora-advanced.apk

where adb >nul 2>nul
if errorlevel 1 (
  if exist "%~dp0platform-tools\adb.exe" (set "PATH=%~dp0platform-tools;%PATH%") else (
    echo adb was not found. Download "SDK Platform-Tools for Windows" from developer.android.com/tools/releases/platform-tools,
    echo unzip it so that the folder "platform-tools" sits next to this file, then run this file again.
    pause & exit /b 1
  )
)
if not exist "%APK%" (
  echo The file flora-advanced.apk is not next to this script. Put both in the same folder.
  pause & exit /b 1
)
echo Looking for your phone...
adb start-server >nul 2>nul
adb devices | findstr /R /C:"	device$" >nul
if errorlevel 1 (
  echo No phone found. On the phone: turn on USB debugging, plug in the cable, and tap Allow on the "Allow USB debugging?" question.
  echo See the steps on the Flora page, then run this file again.
  pause & exit /b 1
)
echo Installing Flora. This takes a minute...
adb install -r "%APK%"
if errorlevel 1 (
  echo Install failed. If it says the signature does not match, an older Flora from another source is installed: uninstall it on the phone first.
  pause & exit /b 1
)
echo Allowing Android's restricted settings for Flora, so you can switch on phone control and message reading yourself...
adb shell cmd appops set %PKG% ACCESS_RESTRICTED_SETTINGS allow
echo.
echo Done. On the phone open Flora. When she asks, switch on her access in Settings (Accessibility and Notification access). You can unplug now.
pause
