Skip to content

Commit

Permalink
chore: Update Unix adapter dependencies (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
DataTriny authored Sep 23, 2023
1 parent 4fc7846 commit 05febcb
Show file tree
Hide file tree
Showing 11 changed files with 318 additions and 168 deletions.
357 changes: 255 additions & 102 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions platforms/unix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ edition = "2021"

[features]
default = ["async-io"]
async-io = ["zbus/async-io"]
tokio = ["dep:tokio", "zbus/tokio"]
async-io = ["atspi/async-std", "zbus/async-io"]
tokio = ["dep:tokio", "atspi/tokio", "zbus/tokio"]

[dependencies]
accesskit = { version = "0.11.2", path = "../../common" }
accesskit_consumer = { version = "0.15.2", path = "../../consumer" }
async-channel = "1.8.0"
async-channel = "1.9"
async-once-cell = "0.5.3"
atspi = { version = "0.10.1", default-features = false }
futures-lite = "1.12.0"
atspi = { version = "0.19", default-features = false }
futures-lite = "1.13"
once_cell = "1.17.1"
serde = "1.0"
tokio = { version = "1.10.0", optional = true, features = ["rt", "net", "time"] }
zbus = { version = "3.6", default-features = false }

tokio = { version = "1.32.0", optional = true, features = ["rt", "net", "time"] }
zbus = { version = "3.14", default-features = false }
5 changes: 4 additions & 1 deletion platforms/unix/src/atspi/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use crate::{
PlatformRootNode,
};
use async_once_cell::OnceCell;
use atspi::{bus::BusProxy, socket::SocketProxy, EventBody};
use atspi::{
events::EventBody,
proxy::{bus::BusProxy, socket::SocketProxy},
};
use serde::Serialize;
use std::{
collections::HashMap,
Expand Down
36 changes: 18 additions & 18 deletions platforms/unix/src/atspi/interfaces/accessible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
atspi::{ObjectId, OwnedObjectAddress},
PlatformNode, PlatformRootNode,
};
use atspi::{accessible::Role, Interface, InterfaceSet, StateSet};
use atspi::{Interface, InterfaceSet, Role, StateSet};
use zbus::{fdo, names::OwnedUniqueName, MessageHeader};

pub(crate) struct AccessibleInterface<T> {
Expand All @@ -24,26 +24,25 @@ impl<T> AccessibleInterface<T> {
#[dbus_interface(name = "org.a11y.atspi.Accessible")]
impl AccessibleInterface<PlatformNode> {
#[dbus_interface(property)]
fn name(&self) -> String {
self.node.name().unwrap_or_default()
fn name(&self) -> fdo::Result<String> {
self.node.name()
}

#[dbus_interface(property)]
fn description(&self) -> String {
self.node.description().unwrap_or_default()
fn description(&self) -> fdo::Result<String> {
self.node.description()
}

#[dbus_interface(property)]
fn parent(&self) -> OwnedObjectAddress {
match self.node.parent() {
Ok(parent) => parent.to_address(self.bus_name.clone()),
_ => OwnedObjectAddress::null(self.bus_name.clone()),
}
fn parent(&self) -> fdo::Result<OwnedObjectAddress> {
self.node
.parent()
.map(|parent| parent.to_address(self.bus_name.clone()))
}

#[dbus_interface(property)]
fn child_count(&self) -> i32 {
self.node.child_count().unwrap_or(0)
fn child_count(&self) -> fdo::Result<i32> {
self.node.child_count()
}

#[dbus_interface(property)]
Expand Down Expand Up @@ -103,7 +102,7 @@ impl AccessibleInterface<PlatformNode> {
#[dbus_interface(name = "org.a11y.atspi.Accessible")]
impl AccessibleInterface<PlatformRootNode> {
#[dbus_interface(property)]
fn name(&self) -> String {
fn name(&self) -> fdo::Result<String> {
self.node.name()
}

Expand All @@ -113,14 +112,15 @@ impl AccessibleInterface<PlatformRootNode> {
}

#[dbus_interface(property)]
fn parent(&self) -> OwnedObjectAddress {
self.node
.parent()
.unwrap_or_else(|| OwnedObjectAddress::null(self.bus_name.clone()))
fn parent(&self) -> fdo::Result<OwnedObjectAddress> {
Ok(self
.node
.parent()?
.unwrap_or_else(|| OwnedObjectAddress::null(self.bus_name.clone())))
}

#[dbus_interface(property)]
fn child_count(&self) -> i32 {
fn child_count(&self) -> fdo::Result<i32> {
self.node.child_count()
}

Expand Down
4 changes: 2 additions & 2 deletions platforms/unix/src/atspi/interfaces/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ impl ActionInterface {
#[dbus_interface(name = "org.a11y.atspi.Action")]
impl ActionInterface {
#[dbus_interface(property)]
fn n_actions(&self) -> i32 {
self.0.n_actions().unwrap_or(0)
fn n_actions(&self) -> fdo::Result<i32> {
self.0.n_actions()
}

fn get_description(&self, _index: i32) -> &str {
Expand Down
6 changes: 3 additions & 3 deletions platforms/unix/src/atspi/interfaces/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ pub(crate) struct ApplicationInterface(pub PlatformRootNode);
#[dbus_interface(name = "org.a11y.atspi.Application")]
impl ApplicationInterface {
#[dbus_interface(property)]
fn toolkit_name(&self) -> String {
fn toolkit_name(&self) -> fdo::Result<String> {
self.0.toolkit_name()
}

#[dbus_interface(property)]
fn version(&self) -> String {
fn version(&self) -> fdo::Result<String> {
self.0.toolkit_version()
}

Expand All @@ -26,7 +26,7 @@ impl ApplicationInterface {
}

#[dbus_interface(property)]
fn id(&self) -> i32 {
fn id(&self) -> fdo::Result<i32> {
self.0.id()
}

Expand Down
2 changes: 1 addition & 1 deletion platforms/unix/src/atspi/interfaces/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
atspi::{OwnedObjectAddress, Rect},
PlatformNode,
};
use atspi::{component::Layer, CoordType};
use atspi::{CoordType, Layer};
use zbus::{fdo, MessageHeader};

pub(crate) struct ComponentInterface {
Expand Down
2 changes: 1 addition & 1 deletion platforms/unix/src/atspi/interfaces/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// the LICENSE-MIT file), at your option.

use crate::atspi::{ObjectId, Rect};
use atspi::{accessible::Role, State};
use atspi::{Role, State};

pub(crate) enum Event {
Object {
Expand Down
21 changes: 11 additions & 10 deletions platforms/unix/src/atspi/interfaces/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// the LICENSE-MIT file), at your option.

use crate::PlatformNode;
use zbus::fdo;

pub(crate) struct ValueInterface {
node: PlatformNode,
Expand All @@ -18,27 +19,27 @@ impl ValueInterface {
#[dbus_interface(name = "org.a11y.atspi.Value")]
impl ValueInterface {
#[dbus_interface(property)]
fn minimum_value(&self) -> f64 {
self.node.minimum_value().unwrap()
fn minimum_value(&self) -> fdo::Result<f64> {
self.node.minimum_value()
}

#[dbus_interface(property)]
fn maximum_value(&self) -> f64 {
self.node.maximum_value().unwrap()
fn maximum_value(&self) -> fdo::Result<f64> {
self.node.maximum_value()
}

#[dbus_interface(property)]
fn minimum_increment(&self) -> f64 {
self.node.minimum_increment().unwrap()
fn minimum_increment(&self) -> fdo::Result<f64> {
self.node.minimum_increment()
}

#[dbus_interface(property)]
fn current_value(&self) -> f64 {
self.node.current_value().unwrap()
fn current_value(&self) -> fdo::Result<f64> {
self.node.current_value()
}

#[dbus_interface(property)]
fn set_current_value(&self, value: f64) {
self.node.set_current_value(value).unwrap();
fn set_current_value(&mut self, value: f64) -> fdo::Result<()> {
self.node.set_current_value(value)
}
}
9 changes: 5 additions & 4 deletions platforms/unix/src/atspi/object_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.

use atspi::Accessible;
use serde::{Deserialize, Serialize};
use zbus::{
names::{OwnedUniqueName, UniqueName},
Expand Down Expand Up @@ -30,11 +31,11 @@ impl OwnedObjectAddress {
}
}

impl From<(String, OwnedObjectPath)> for OwnedObjectAddress {
fn from(value: (String, OwnedObjectPath)) -> Self {
impl From<Accessible> for OwnedObjectAddress {
fn from(object: Accessible) -> Self {
Self {
bus_name: OwnedUniqueName::from(UniqueName::from_string_unchecked(value.0)),
path: value.1,
bus_name: OwnedUniqueName::from(UniqueName::from_string_unchecked(object.name)),
path: object.path,
}
}
}
29 changes: 11 additions & 18 deletions platforms/unix/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ use accesskit::{
};
use accesskit_consumer::{DetachedNode, FilterResult, Node, NodeState, TreeState};
use async_channel::Sender;
use atspi::{
accessible::Role as AtspiRole, component::Layer, CoordType, Interface, InterfaceSet, State,
StateSet,
};
use atspi::{CoordType, Interface, InterfaceSet, Layer, Role as AtspiRole, State, StateSet};
use std::{
iter::FusedIterator,
sync::{Arc, RwLock, RwLockReadGuard, Weak},
Expand Down Expand Up @@ -997,20 +994,19 @@ impl PlatformRootNode {
Err(unknown_object(&self.accessible_id()))
}

pub(crate) fn name(&self) -> String {
pub(crate) fn name(&self) -> fdo::Result<String> {
self.resolve_app_context(|context| Ok(context.name.clone()))
.unwrap_or_default()
}

pub(crate) fn parent(&self) -> Option<OwnedObjectAddress> {
pub(crate) fn parent(&self) -> fdo::Result<Option<OwnedObjectAddress>> {
self.resolve_app_context(|context| Ok(context.desktop_address.clone()))
.ok()
.flatten()
}

pub(crate) fn child_count(&self) -> i32 {
self.resolve_app_context(|context| Ok(i32::try_from(context.adapters.len()).unwrap_or(-1)))
.unwrap_or(-1)
pub(crate) fn child_count(&self) -> fdo::Result<i32> {
self.resolve_app_context(|context| {
i32::try_from(context.adapters.len())
.map_err(|_| fdo::Error::Failed("Too many children.".into()))
})
}

pub(crate) fn accessible_id(&self) -> ObjectId {
Expand Down Expand Up @@ -1046,19 +1042,16 @@ impl PlatformRootNode {
})
}

pub(crate) fn toolkit_name(&self) -> String {
pub(crate) fn toolkit_name(&self) -> fdo::Result<String> {
self.resolve_app_context(|context| Ok(context.toolkit_name.clone()))
.unwrap_or_default()
}

pub(crate) fn toolkit_version(&self) -> String {
pub(crate) fn toolkit_version(&self) -> fdo::Result<String> {
self.resolve_app_context(|context| Ok(context.toolkit_version.clone()))
.unwrap_or_default()
}

pub(crate) fn id(&self) -> i32 {
pub(crate) fn id(&self) -> fdo::Result<i32> {
self.resolve_app_context(|context| Ok(context.id.unwrap_or(-1)))
.unwrap_or(-1)
}

pub(crate) fn set_id(&mut self, id: i32) -> fdo::Result<()> {
Expand Down

0 comments on commit 05febcb

Please sign in to comment.