Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
Rearange action flow in pairing program
Browse files Browse the repository at this point in the history
  • Loading branch information
jkcoxson committed Apr 29, 2022
1 parent 42fec7a commit baf699e
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ fn main() {
}
let device = device.unwrap();

// Get the pairing code
println!("Please enter the code you got from the shortcut");
let mut launch_code = String::new();
std::io::stdin().read_line(&mut launch_code).unwrap();
launch_code = launch_code.trim().to_string();

loop {
// Attempt to use already generated pair file to avoid nullifying old pairing files
// Fetch the pairing file from the system
let pair_record = match userpref::read_pair_record(device.get_udid()) {
Ok(pair_record) => Some(pair_record),
Err(e) => {
Expand All @@ -85,12 +91,6 @@ fn main() {
let pair_record = pair_record.to_string();
let pair_record: Vec<u8> = pair_record.into_bytes();

// Ask the user for the launch code
println!("Please enter the code you got from the shortcut");
let mut launch_code = String::new();
std::io::stdin().read_line(&mut launch_code).unwrap();
launch_code = launch_code.trim().to_string();

// Yeet this bad boi off to JitStreamer
let client = reqwest::blocking::Client::new();
let res = client
Expand All @@ -109,7 +109,7 @@ fn main() {
}
};
if res["success"].as_bool().unwrap() {
println!("Successfully paired!");
println!("\nSuccessfully paired! Press ok on the shortcut now.");
wait_for_enter();
return;
} else {
Expand All @@ -123,6 +123,7 @@ fn main() {
}
}

// Fetching the pairing record failed, so we need to generate a new one
let lockdown_client = match device.new_lockdownd_client("jit_streamer_pair".to_string()) {
Ok(lockdown_client) => lockdown_client,
Err(e) => {
Expand All @@ -131,6 +132,15 @@ fn main() {
}
};

// Turn on WiFi sync so JitStreamer can pair
lockdown_client
.set_value(
"EnableWifiDebugging".to_string(),
"com.apple.mobile.wireless_lockdown".to_string(),
true.into(),
)
.unwrap();

loop {
match lockdown_client.pair(None, None) {
Ok(()) => break,
Expand Down

0 comments on commit baf699e

Please sign in to comment.