iphone-cli 0.1.8

Let AI agents read and operate any app on a real iPhone through the accessibility tree. No XCUITest, WebDriverAgent or Xcode signing.
Documentation
//! `iph setup`: run the doctor, explain what is missing, wait for the user to
//! fix it on the phone, and check again.

use std::io::{BufRead, IsTerminal, Write};

use serde_json::json;

use crate::{client, human, i18n::t};

pub async fn run(udid: &str, fix_wifi: bool) -> i32 {
    let interactive = std::io::stdin().is_terminal();
    println!(
        "{}",
        t(
            "iph 준비 상태를 확인합니다. 터치 확인을 위해 폰에서 설정 앱이 열리고 목록이 한 번 내려갔다 올라옵니다.",
            "Checking that the phone is ready for iph. To test touch, Settings opens on the phone and its list scrolls down and back once.",
        )
    );
    if fix_wifi {
        println!("{}", t(
            "--fix-wifi: USB로 연결된 폰의 지원되는 무선 연결/디버깅 플래그를 켭니다.",
            "--fix-wifi: enabling supported wireless connection/debugging flags on the USB-connected phone.",
        ));
    }
    loop {
        let v = client::request(udid, "doctor", json!({ "fix_wifi": fix_wifi })).await;
        println!("{}", human::render("doctor", &v));
        if v["ready"] == true {
            println!(
                "{}",
                t(
                    "준비됐습니다. `iph read`로 화면을 읽어 보세요.",
                    "Ready. Try `iph read`."
                )
            );
            return 0;
        }
        if !interactive {
            return 1;
        }
        print!(
            "{}",
            t(
                "위 안내대로 한 뒤 Enter를 누르면 다시 확인합니다 (그만두려면 q): ",
                "Do the steps above, then press Enter to check again (q to quit): ",
            )
        );
        std::io::stdout().flush().ok();
        let mut line = String::new();
        if std::io::stdin().lock().read_line(&mut line).is_err() || line.trim() == "q" {
            return 1;
        }
    }
}