#[cfg(windows)]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
use mtp_rs::{Backend, MtpDevice};
use std::time::{Duration, Instant};
use tokio::time::timeout;
let device = MtpDevice::builder()
.backend(Backend::Wpd)
.open_first()
.await?;
let info = device.device_info();
println!(
"Device: {} {} (serial {:?})",
info.manufacturer, info.model, info.serial_number
);
println!(
"supports_events = {}",
device.capabilities().supports_events
);
println!("\nWatching for events for 30s — change the device by hand now...\n");
let deadline = Instant::now() + Duration::from_secs(30);
let mut count = 0u32;
while Instant::now() < deadline {
let remaining = deadline.saturating_duration_since(Instant::now());
match timeout(remaining.min(Duration::from_secs(5)), device.next_event()).await {
Ok(Ok(event)) => {
count += 1;
println!(" event #{count}: {event:?}");
}
Ok(Err(e)) => {
println!(" next_event error: {e} (stopping)");
break;
}
Err(_) => { }
}
}
println!("\nDone. Observed {count} event(s).");
device.close().await?;
Ok(())
}
#[cfg(not(windows))]
fn main() {
eprintln!("wpd_events is Windows-only.");
}