Skip to content

Commit

Permalink
Merge pull request #182 from odilia-app/objectref2accessibleproxy
Browse files Browse the repository at this point in the history
Obtain an `AccessibleProxy` from any `ObjectRef` with `ObjectRefExt`
  • Loading branch information
TTWNO authored May 8, 2024
2 parents 596ad05 + 85d7518 commit 5c684a9
Showing 1 changed file with 37 additions and 0 deletions.
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

0 comments on commit 5c684a9

Please sign in to comment.