Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB Portal #210

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

USB Portal #210

wants to merge 6 commits into from

Conversation

hfiguiere
Copy link
Contributor

This is a draft, needs a lot of cleanup. Also the portal hasn't landed yet.

But I'm using this to exercise / test the USB portal.

@hfiguiere hfiguiere force-pushed the usb-portal branch 3 times, most recently from fced97d to ecb8189 Compare May 20, 2024 02:33
@hfiguiere
Copy link
Contributor Author

Currently includes a revert for #208

@hfiguiere hfiguiere force-pushed the usb-portal branch 3 times, most recently from 4d81103 to de86287 Compare May 20, 2024 03:10
@hfiguiere
Copy link
Contributor Author

The build failure is because it needs a flatpak version that isn't available.

Signed-off-by: Hubert Figuière <hub@figuiere.net>
This allow running the release build.

Signed-off-by: Hubert Figuière <hub@figuiere.net>
Signed-off-by: Hubert Figuière <hub@figuiere.net>
Signed-off-by: Hubert Figuière <hub@figuiere.net>
- Added UI for USB

Signed-off-by: Hubert Figuière <hub@figuiere.net>
…evice

Added rusb to the crates.
Added libusb to the manifest.

Signed-off-by: Hubert Figuière <hub@figuiere.net>
#[doc(alias = "EnumerateDevices")]
pub async fn enumerate_devices(
&self,
options: UsbOptions,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no options here, so just pass Default? Also seems to have both a request_handle, yet it doesn't use the mechanism for requests and do a plain dbus call?

#[doc(alias = "AcquireDevices")]
pub async fn acquire_devices(
&self,
parent_window: &WindowIdentifier,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should become Option<&WindowIdentifier> with the changes in main.

pub async fn acquire_devices(
&self,
parent_window: &WindowIdentifier,
devices: &[(&String, bool)],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are those string/bool supposed to be? I haven't looked at the spec, but it would be nice to clarify their meaning. If they are returned by some other method call, then they should have an alias to make it easier to use.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see from the rest of the code, imho, make it take a new type called `Device(String /* ID */ , bool / * writable */); or so.

/// Option for AcquireDevice call.
#[derive(SerializeDict, Type, Debug, Default)]
#[zvariant(signature = "dict")]
pub struct AcquireOptions {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no reason for making this struct public

}

/// Call on success of acquire_devices.
#[doc(alias = "FinishAcquireDevices")]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it can be just called at the end of acquire_device, why it is a separate method?

async move {
let root = row.native().unwrap();
let identifier = WindowIdentifier::from_native(&root).await;
let usb = UsbProxy::new().await.unwrap();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unwraps here are not good, once you move it to a separate function, you can make it report errors using the notifications support in PortalPage

#[strong]
page,
async move {
let usb = UsbProxy::new().await.unwrap();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the proxy around

}
));
let device_id = device.0.clone();
row.connect_unshare_clicked(clone!(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, move it to a separate function

self.session.lock().await.replace(session);

let session = self.session.clone();
glib::spawn_future(async move {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already async, no need for using glib here


pub(super) async fn stop_session(&self) -> anyhow::Result<()> {
if let Some(session) = self.session.lock().await.take() {
session.close().await?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should switch the buttons state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants