Skip to content

Commit

Permalink
demo: Call FinishAcquireDevice for USB
Browse files Browse the repository at this point in the history
Signed-off-by: Hubert Figuière <[email protected]>
  • Loading branch information
hfiguiere committed May 20, 2024
1 parent 2395600 commit adee7f8
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions ashpd-demo/src/portals/desktop/usb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ mod imp {

let device_id = device.0.clone();
let device_writable = device.1.writable.unwrap_or(false);
activatable.connect_clicked(move |row| {
glib::spawn_future_local(clone!(@strong row, @strong device_id => async move {
activatable.connect_clicked(clone!(@strong page => move |row| {
glib::spawn_future_local(clone!(@strong row, @strong device_id, @strong page => async move {
let root = row.native().unwrap();
let identifier = WindowIdentifier::from_native(&root).await;
let usb = UsbProxy::new().await.unwrap();
Expand All @@ -82,12 +82,35 @@ mod imp {
let result = usb.acquire_devices(&identifier, &[
(&device_id, device_writable)
]).await;
println!("result: {result:?}");
match result {
Ok(_) => {
loop {
let result = usb.finish_acquire_devices().await;
match result {
Ok(result) => {
println!("result {result:?}");
if !result.1 {
continue;
}
}
Err(err) => {
tracing::error!("Finish acquire device error: {err}");
page.error(&format!("Finish acquire device error: {err}"));
}
}
break;
}
},
Err(err) => {
tracing::error!("Acquire device error: {err}");
page.error(&format!("Acquire device error: {err}"));
}
}
// } else {
// let _ = usb.release_devices(&[&device_id]).await;
// }
}));
});
}));
page.imp().add(device.0.clone(), &row);
}
Ok(())
Expand Down

0 comments on commit adee7f8

Please sign in to comment.