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 4 commits into
base: master
Choose a base branch
from
Draft

USB Portal #210

wants to merge 4 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.

src/desktop/usb.rs Outdated Show resolved Hide resolved
src/desktop/usb.rs Outdated Show resolved Hide resolved
src/desktop/usb.rs Outdated Show resolved Hide resolved
src/desktop/usb.rs Outdated Show resolved Hide resolved
src/desktop/usb.rs Show resolved Hide resolved
ashpd-demo/src/portals/desktop/usb.rs Outdated Show resolved Hide resolved
#[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

ashpd-demo/src/portals/desktop/usb.rs Outdated Show resolved Hide resolved
ashpd-demo/src/portals/desktop/usb.rs Outdated Show resolved Hide resolved

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is done by the non-imp version which is the one called from the UI.

@hfiguiere hfiguiere force-pushed the usb-portal branch 3 times, most recently from 3aee673 to 9146631 Compare November 23, 2024 07:33
@hfiguiere hfiguiere force-pushed the usb-portal branch 2 times, most recently from 7eadba8 to 7697720 Compare December 7, 2024 03:06
Signed-off-by: Hubert Figuière <[email protected]>
This allow running the release build.

Signed-off-by: Hubert Figuière <[email protected]>
@@ -13,6 +13,8 @@
"--share=ipc",
"--socket=wayland",
"--device=dri",
"--own-name=com.belmoussaoui.ashpd.demo",
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this needed? Isn't this only to own names for app ids which don't match the app id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use this build using fenv, and that allow to build and run the non "Devel" version. It's not required for this PR per see (hint it's still in draft).

<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<style>
<class name="linked" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

In think the consensus is that we want to avoid linked buttons whenever possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

link (to the documentation) ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is none, ask in the #design:gnome.org room if you would like more context.

ashpd-demo/src/portals/desktop/usb.rs Outdated Show resolved Hide resolved
ashpd-demo/src/portals/desktop/usb.rs Outdated Show resolved Hide resolved
pub struct UsbDevice {
parent: Option<String>,
readable: Option<bool>,
/// Device is writable. Default is false.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an option, please document None. Ditto for readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Default is false". I thought this was clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

documented readable. (cf the D-Bus xml)

Copy link
Collaborator

Choose a reason for hiding this comment

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

What does None mean? How is it different from false? Why would you get one over the other?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because it's the a{sv} from D-Bus. As per the D-Bus interface it can be omitted so it has to be omittable here.

@hfiguiere hfiguiere force-pushed the usb-portal branch 2 times, most recently from 5d2cff3 to 85d3611 Compare December 7, 2024 16:46
Signed-off-by: Hubert Figuière <[email protected]>
- Added UI for USB
- Added rusb to the crates.
- Added libusb to the manifest.

Signed-off-by: Hubert Figuière <[email protected]>
@@ -50,14 +62,15 @@
{
"name": "ashpd-demo",
Copy link
Owner

Choose a reason for hiding this comment

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

I rather have a change that puts the manifest in ./ and see if that helps? :)

}
}

mod imp {
Copy link
Owner

Choose a reason for hiding this comment

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

This doesn't follow the current code style that puts mod imp at the top of the file

impl ActionRowImpl for UsbDeviceRow {}

#[derive(Debug, gtk::CompositeTemplate, Default)]
#[template(resource = "/com/belmoussaoui/ashpd/demo/usb.ui")]
Copy link
Owner

Choose a reason for hiding this comment

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

@@ -268,7 +268,8 @@ where
self.0.call("Close", &()).await
}

pub(crate) fn path(&self) -> &ObjectPath<'_> {
/// Return the object path of the request.
pub fn path(&self) -> &ObjectPath<'_> {
Copy link
Owner

Choose a reason for hiding this comment

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

Why was this made public?

Comment on lines +60 to +71
pub struct UsbDevice {
parent: Option<String>,
/// Device can be opened for reading. Default is false.
readable: Option<bool>,
/// Device can be opened for writing. Default is false.
pub writable: Option<bool>,
/// The device node for the USB.
#[zvariant(rename = "device-file")]
pub device_file: Option<String>,
/// Device properties
pub properties: Option<HashMap<String, OwnedValue>>,
}
Copy link
Owner

Choose a reason for hiding this comment

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

The way we deal with structs in general is that no field is public, only add getters or setters that would be public. This allow us to change the way we deserialize/serialize things without impacting the public API.

#[zvariant(signature = "dict")]
struct AcquiredDevice {
success: bool,
fd: Option<OwnedFd>,
Copy link
Owner

Choose a reason for hiding this comment

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

So if success = true, do we always receive an fd or not? or if the success = true and fd = None, there are no more fds to acquire?

#[doc(alias = "FinishAcquireDevices")]
async fn finish_acquire_devices(
&self,
handle_token: &ObjectPath<'_>,
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this param called handle_token? is it really one or a request path?

Ok(Self(proxy))
}

/// Create Session
Copy link
Owner

Choose a reason for hiding this comment

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

Please follow the doc style for proxies that are public.

Comment on lines +233 to +235
let mut result = self.finish_acquire_devices(path).await?;
let finished = result.1;
devices.append(&mut result.0);
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
let mut result = self.finish_acquire_devices(path).await?;
let finished = result.1;
devices.append(&mut result.0);
let (new_devices, finished) = self.finish_acquire_devices(path).await?;
devices.append(&new_devices);

?

}

/// Device to acquire
pub struct Device(pub String /* ID */, pub bool /* writable */);
Copy link
Owner

Choose a reason for hiding this comment

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

This needs a constructor/getters


/// USB error for acquiring device.
#[derive(Debug)]
pub struct UsbError(pub Option<String>);
Copy link
Owner

Choose a reason for hiding this comment

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

Needs to implement std::error::Error

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.

3 participants