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

Obtain an AccessibleProxy from any ObjectRef with ObjectRefExt #182

Merged
merged 3 commits into from
May 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions atspi-proxies/src/accessible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ impl TryFrom<AccessibleProxy<'_>> for ObjectRef {
})
}
}

impl TryFrom<&AccessibleProxy<'_>> for ObjectRef {
type Error = AtspiError;
fn try_from(proxy: &AccessibleProxy<'_>) -> Result<ObjectRef, Self::Error> {
Expand All @@ -248,6 +249,42 @@ impl TryFrom<&AccessibleProxy<'_>> for ObjectRef {
}
}

pub trait ObjectRefExt {
/// Returns an [`AccessibleProxy`], the handle to the object's `Accessible` interface.
///
/// # Errors
///
/// `BusName` or `ObjectPath` are assumed to be valid because they are obtained from a valid `ObjectRef`.
/// If the builder is lacking the necessary parameters to build a proxy. See [`zbus::ProxyBuilder::build`].
/// If this method fails, you may want to check the `AccessibleProxy` default values for missing / invalid parameters.
fn as_accessible_proxy(
&self,
conn: &zbus::Connection,
) -> impl std::future::Future<Output = Result<AccessibleProxy<'_>, zbus::Error>> + Send;
}

impl ObjectRefExt for ObjectRef {
async fn as_accessible_proxy(
&self,
conn: &zbus::Connection,
) -> Result<AccessibleProxy<'_>, zbus::Error> {
let builder = AccessibleProxy::builder(conn).destination(self.name.as_str());
let Ok(builder) = builder else {
return Err(builder.unwrap_err());
};

let builder = builder.path(self.path.as_str());
let Ok(builder) = builder else {
return Err(builder.unwrap_err());
};

builder
.cache_properties(zbus::proxy::CacheProperties::No)
.build()
.await
}
}

impl PartialEq for AccessibleProxy<'_> {
fn eq<'a>(&self, other: &Self) -> bool {
self.inner().path() == other.inner().path()
Expand Down
Loading