@@ -13,7 +13,7 @@ use crate::{
13
13
} ,
14
14
context:: Context ,
15
15
node:: { filter, filter_detached, NodeWrapper , PlatformNode } ,
16
- util:: AppContext ,
16
+ util:: { block_on , AppContext } ,
17
17
} ;
18
18
use accesskit:: { ActionHandler , NodeId , Rect , Role , TreeUpdate } ;
19
19
use accesskit_consumer:: { DetachedNode , FilterResult , Node , Tree , TreeChangeHandler , TreeState } ;
@@ -39,10 +39,12 @@ impl Adapter {
39
39
initial_state : impl ' static + FnOnce ( ) -> TreeUpdate ,
40
40
action_handler : Box < dyn ActionHandler + Send + Sync > ,
41
41
) -> Option < Self > {
42
- let mut atspi_bus = Bus :: a11y_bus ( ) ?;
42
+ let mut atspi_bus = block_on ( async { Bus :: a11y_bus ( ) . await } ) ?;
43
43
let ( event_sender, event_receiver) = async_channel:: unbounded ( ) ;
44
44
let atspi_bus_copy = atspi_bus. clone ( ) ;
45
- let event_task = atspi_bus. connection ( ) . inner ( ) . executor ( ) . spawn (
45
+ #[ cfg( feature = "tokio" ) ]
46
+ let _guard = crate :: util:: TOKIO_RT . enter ( ) ;
47
+ let event_task = atspi_bus. connection ( ) . executor ( ) . spawn (
46
48
async move {
47
49
handle_events ( atspi_bus_copy, event_receiver) . await ;
48
50
} ,
@@ -51,7 +53,7 @@ impl Adapter {
51
53
let tree = Tree :: new ( initial_state ( ) ) ;
52
54
let app_context = AppContext :: new ( app_name, toolkit_name, toolkit_version) ;
53
55
let context = Context :: new ( tree, action_handler, app_context) ;
54
- atspi_bus. register_root_node ( & context) . ok ( ) ?;
56
+ block_on ( async { atspi_bus. register_root_node ( & context) . await . ok ( ) } ) ?;
55
57
let adapter = Adapter {
56
58
atspi_bus,
57
59
_event_task : event_task,
@@ -85,31 +87,47 @@ impl Adapter {
85
87
fn register_interfaces ( & self , id : NodeId , new_interfaces : InterfaceSet ) -> zbus:: Result < bool > {
86
88
let path = format ! ( "{}{}" , ACCESSIBLE_PATH_PREFIX , ObjectId :: from( id) . as_str( ) ) ;
87
89
if new_interfaces. contains ( Interface :: Accessible ) {
88
- self . atspi_bus . register_interface (
89
- & path,
90
- AccessibleInterface :: new (
91
- self . atspi_bus . unique_name ( ) . to_owned ( ) ,
92
- PlatformNode :: new ( & self . context , id) ,
93
- ) ,
94
- ) ?;
90
+ block_on ( async {
91
+ self . atspi_bus
92
+ . register_interface (
93
+ & path,
94
+ AccessibleInterface :: new (
95
+ self . atspi_bus . unique_name ( ) . to_owned ( ) ,
96
+ PlatformNode :: new ( & self . context , id) ,
97
+ ) ,
98
+ )
99
+ . await
100
+ } ) ?;
95
101
}
96
102
if new_interfaces. contains ( Interface :: Action ) {
97
- self . atspi_bus . register_interface (
98
- & path,
99
- ActionInterface :: new ( PlatformNode :: new ( & self . context , id) ) ,
100
- ) ?;
103
+ block_on ( async {
104
+ self . atspi_bus
105
+ . register_interface (
106
+ & path,
107
+ ActionInterface :: new ( PlatformNode :: new ( & self . context , id) ) ,
108
+ )
109
+ . await
110
+ } ) ?;
101
111
}
102
112
if new_interfaces. contains ( Interface :: Component ) {
103
- self . atspi_bus . register_interface (
104
- & path,
105
- ComponentInterface :: new ( PlatformNode :: new ( & self . context , id) ) ,
106
- ) ?;
113
+ block_on ( async {
114
+ self . atspi_bus
115
+ . register_interface (
116
+ & path,
117
+ ComponentInterface :: new ( PlatformNode :: new ( & self . context , id) ) ,
118
+ )
119
+ . await
120
+ } ) ?;
107
121
}
108
122
if new_interfaces. contains ( Interface :: Value ) {
109
- self . atspi_bus . register_interface (
110
- & path,
111
- ValueInterface :: new ( PlatformNode :: new ( & self . context , id) ) ,
112
- ) ?;
123
+ block_on ( async {
124
+ self . atspi_bus
125
+ . register_interface (
126
+ & path,
127
+ ValueInterface :: new ( PlatformNode :: new ( & self . context , id) ) ,
128
+ )
129
+ . await
130
+ } ) ?;
113
131
}
114
132
Ok ( true )
115
133
}
@@ -119,24 +137,30 @@ impl Adapter {
119
137
id : & ObjectId ,
120
138
old_interfaces : InterfaceSet ,
121
139
) -> zbus:: Result < bool > {
122
- let path = format ! ( "{}{}" , ACCESSIBLE_PATH_PREFIX , id. as_str( ) ) ;
123
- if old_interfaces. contains ( Interface :: Accessible ) {
124
- self . atspi_bus
125
- . unregister_interface :: < AccessibleInterface < PlatformNode > > ( & path) ?;
126
- }
127
- if old_interfaces. contains ( Interface :: Action ) {
128
- self . atspi_bus
129
- . unregister_interface :: < ActionInterface > ( & path) ?;
130
- }
131
- if old_interfaces. contains ( Interface :: Component ) {
132
- self . atspi_bus
133
- . unregister_interface :: < ComponentInterface > ( & path) ?;
134
- }
135
- if old_interfaces. contains ( Interface :: Value ) {
136
- self . atspi_bus
137
- . unregister_interface :: < ValueInterface > ( & path) ?;
138
- }
139
- Ok ( true )
140
+ block_on ( async {
141
+ let path = format ! ( "{}{}" , ACCESSIBLE_PATH_PREFIX , id. as_str( ) ) ;
142
+ if old_interfaces. contains ( Interface :: Accessible ) {
143
+ self . atspi_bus
144
+ . unregister_interface :: < AccessibleInterface < PlatformNode > > ( & path)
145
+ . await ?;
146
+ }
147
+ if old_interfaces. contains ( Interface :: Action ) {
148
+ self . atspi_bus
149
+ . unregister_interface :: < ActionInterface > ( & path)
150
+ . await ?;
151
+ }
152
+ if old_interfaces. contains ( Interface :: Component ) {
153
+ self . atspi_bus
154
+ . unregister_interface :: < ComponentInterface > ( & path)
155
+ . await ?;
156
+ }
157
+ if old_interfaces. contains ( Interface :: Value ) {
158
+ self . atspi_bus
159
+ . unregister_interface :: < ValueInterface > ( & path)
160
+ . await ?;
161
+ }
162
+ Ok ( true )
163
+ } )
140
164
}
141
165
142
166
pub fn set_root_window_bounds ( & self , outer : Rect , inner : Rect ) {
0 commit comments