1use std::io::{BufRead, IsTerminal, Write};
5
6use serde_json::json;
7
8use crate::{client, human, i18n::t};
9
10pub async fn run(udid: &str, fix_wifi: bool) -> i32 {
11 let interactive = std::io::stdin().is_terminal();
12 println!(
13 "{}",
14 t(
15 "iph 준비 상태를 확인합니다. 터치 확인을 위해 폰에서 설정 앱이 열리고 목록이 한 번 내려갔다 올라옵니다.",
16 "Checking that the phone is ready for iph. To test touch, Settings opens on the phone and its list scrolls down and back once.",
17 )
18 );
19 if fix_wifi {
20 println!("{}", t(
21 "--fix-wifi: USB로 연결된 폰의 지원되는 무선 연결/디버깅 플래그를 켭니다.",
22 "--fix-wifi: enabling supported wireless connection/debugging flags on the USB-connected phone.",
23 ));
24 }
25 loop {
26 let v = client::request(udid, "doctor", json!({ "fix_wifi": fix_wifi })).await;
27 println!("{}", human::render("doctor", &v));
28 if v["ready"] == true {
29 println!(
30 "{}",
31 t(
32 "준비됐습니다. `iph read`로 화면을 읽어 보세요.",
33 "Ready. Try `iph read`."
34 )
35 );
36 return 0;
37 }
38 if !interactive {
39 return 1;
40 }
41 print!(
42 "{}",
43 t(
44 "위 안내대로 한 뒤 Enter를 누르면 다시 확인합니다 (그만두려면 q): ",
45 "Do the steps above, then press Enter to check again (q to quit): ",
46 )
47 );
48 std::io::stdout().flush().ok();
49 let mut line = String::new();
50 if std::io::stdin().lock().read_line(&mut line).is_err() || line.trim() == "q" {
51 return 1;
52 }
53 }
54}