Refactor idevice tools into single binary

This commit is contained in:
Jackson Coxson
2026-01-03 16:58:33 -07:00
parent 2eebbff172
commit 189dd5caf2
34 changed files with 1983 additions and 2777 deletions

View File

@@ -1,69 +1,20 @@
use clap::{Arg, Command};
use idevice::{IdeviceService, RsdService, core_device_proxy::CoreDeviceProxy, rsd::RsdHandshake};
use idevice::{
IdeviceService, RsdService, core_device_proxy::CoreDeviceProxy, provider::IdeviceProvider,
rsd::RsdHandshake,
};
use jkcli::{CollectedArguments, JkArgument, JkCommand};
use std::fs;
use idevice::screenshotr::ScreenshotService;
mod common;
pub fn register() -> JkCommand {
JkCommand::new()
.help("Take a screenshot")
.with_argument(JkArgument::new().with_help("Output path").required(true))
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let matches = Command::new("screen_shot")
.about("take screenshot")
.arg(
Arg::new("host")
.long("host")
.value_name("HOST")
.help("IP address of the device"),
)
.arg(
Arg::new("pairing_file")
.long("pairing-file")
.value_name("PATH")
.help("Path to the pairing file"),
)
.arg(
Arg::new("udid")
.value_name("UDID")
.help("UDID of the device (overrides host/pairing file)")
.index(1),
)
.arg(
Arg::new("output")
.short('o')
.long("output")
.value_name("FILE")
.help("Output file path for the screenshot (default: ./screenshot.png)")
.default_value("screenshot.png"),
)
.arg(
Arg::new("about")
.long("about")
.help("Show about information")
.action(clap::ArgAction::SetTrue),
)
.get_matches();
if matches.get_flag("about") {
print!("screen_shot - take screenshot from ios device");
println!("Copyright (c) 2025 Jackson Coxson");
return;
}
let udid = matches.get_one::<String>("udid");
let host = matches.get_one::<String>("host");
let pairing_file = matches.get_one::<String>("pairing_file");
let output_path = matches.get_one::<String>("output").unwrap();
let provider =
match common::get_provider(udid, host, pairing_file, "take_screenshot-jkcoxson").await {
Ok(p) => p,
Err(e) => {
eprintln!("{e}");
return;
}
};
pub async fn main(arguments: &CollectedArguments, provider: Box<dyn IdeviceProvider>) {
let output_path = arguments.clone().next_argument::<String>().unwrap();
let res = if let Ok(proxy) = CoreDeviceProxy::connect(&*provider).await {
println!("Using DVT over CoreDeviceProxy");
@@ -104,7 +55,7 @@ async fn main() {
screenshot_client.take_screenshot().await.unwrap()
};
match fs::write(output_path, res) {
match fs::write(&output_path, res) {
Ok(_) => println!("Screenshot saved to: {}", output_path),
Err(e) => eprintln!("Failed to write screenshot to file: {}", e),
}