mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
Implement new mounter cli
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
// Jackson Coxson
|
||||
// Common functions between tools
|
||||
|
||||
use std::{net::IpAddr, str::FromStr};
|
||||
use std::{
|
||||
net::{IpAddr, SocketAddr},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use idevice::{
|
||||
pairing_file::PairingFile,
|
||||
@@ -17,16 +20,26 @@ pub async fn get_provider(
|
||||
) -> Result<Box<dyn IdeviceProvider>, String> {
|
||||
let provider: Box<dyn IdeviceProvider> = if udid.is_some() {
|
||||
let udid = udid.unwrap();
|
||||
let mut usbmuxd = UsbmuxdConnection::default()
|
||||
.await
|
||||
.expect("Unable to connect to usbmxud");
|
||||
|
||||
let mut usbmuxd = if let Ok(var) = std::env::var("USBMUXD_SOCKET_ADDRESS") {
|
||||
let socket = SocketAddr::from_str(&var).expect("Bad USBMUXD_SOCKET_ADDRESS");
|
||||
let socket = tokio::net::TcpStream::connect(socket)
|
||||
.await
|
||||
.expect("unable to connect to socket address");
|
||||
UsbmuxdConnection::new(Box::new(socket), 1)
|
||||
} else {
|
||||
UsbmuxdConnection::default()
|
||||
.await
|
||||
.expect("Unable to connect to usbmxud")
|
||||
};
|
||||
|
||||
let dev = match usbmuxd.get_device(udid).await {
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
return Err(format!("Device not found: {e:?}"));
|
||||
}
|
||||
};
|
||||
Box::new(dev.to_provider(UsbmuxdAddr::default(), 1, label))
|
||||
Box::new(dev.to_provider(UsbmuxdAddr::from_env_var().unwrap(), 1, label))
|
||||
} else if host.is_some() && pairing_file.is_some() {
|
||||
let host = match IpAddr::from_str(host.unwrap()) {
|
||||
Ok(h) => h,
|
||||
@@ -47,9 +60,17 @@ pub async fn get_provider(
|
||||
label: "ideviceinfo-jkcoxson".to_string(),
|
||||
})
|
||||
} else {
|
||||
let mut usbmuxd = UsbmuxdConnection::default()
|
||||
.await
|
||||
.expect("Unable to connect to usbmxud");
|
||||
let mut usbmuxd = if let Ok(var) = std::env::var("USBMUXD_SOCKET_ADDRESS") {
|
||||
let socket = SocketAddr::from_str(&var).expect("Bad USBMUXD_SOCKET_ADDRESS");
|
||||
let socket = tokio::net::TcpStream::connect(socket)
|
||||
.await
|
||||
.expect("unable to connect to socket address");
|
||||
UsbmuxdConnection::new(Box::new(socket), 1)
|
||||
} else {
|
||||
UsbmuxdConnection::default()
|
||||
.await
|
||||
.expect("Unable to connect to usbmxud")
|
||||
};
|
||||
let devs = match usbmuxd.get_devices().await {
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
@@ -59,7 +80,7 @@ pub async fn get_provider(
|
||||
if devs.is_empty() {
|
||||
return Err("No devices connected!".to_string());
|
||||
}
|
||||
Box::new(devs[0].to_provider(UsbmuxdAddr::default(), 0, label))
|
||||
Box::new(devs[0].to_provider(UsbmuxdAddr::from_env_var().unwrap(), 0, label))
|
||||
};
|
||||
Ok(provider)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user