Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-driver): wake Chromium AT-SPI content before the first application tree traversal (#5074)

injaneitye7af6a61b0c2
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/atspi/native.rs b/libs/cua-driver/rust/crates/platform-linux/src/atspi/native.rs
index f8fbd597b4..eac18f0da6 100644
--- a/libs/cua-driver/rust/crates/platform-linux/src/atspi/native.rs
+++ b/libs/cua-driver/rust/crates/platform-linux/src/atspi/native.rs
@@ -12,7 +12,8 @@
//! `perform_action`, `set_value`, and `get_element_bounds` index into that same
//! ordered set.
-use std::sync::OnceLock;
+use std::collections::HashSet;
+use std::sync::{Mutex, OnceLock};
use std::time::Duration;
use anyhow::{anyhow, Context, Result};
@@ -1332,6 +1333,9 @@ async fn collect_visited_bounded_opts<'a>(
return Ok(None);
}
};
+ if first_application_walk(pid) {
+ let _ = call(app.get_attributes()).await;
+ }
let zconn = conn.connection();
// Mapped popups of this pid, read once and only when a menubar menu's
// open state cannot be told from AT-SPI states alone (gail, focus elsewhere).
@@ -2339,6 +2343,14 @@ fn is_indexable_capabilities(
// ── Public (sync) entry points ───────────────────────────────────────────────
+fn first_application_walk(pid: u32) -> bool {
+ static PIDS: OnceLock<Mutex<HashSet<u32>>> = OnceLock::new();
+ PIDS.get_or_init(|| Mutex::new(HashSet::new()))
+ .lock()
+ .unwrap()
+ .insert(pid)
+}
+
pub fn walk_tree(pid: u32) -> Result<Option<(String, Vec<AtspiNode>)>> {
walk_tree_bounded(pid, 0, None, None)
.map(|snapshot| snapshot.map(|walked| (walked.markdown, walked.nodes)))
@@ -7407,6 +7419,14 @@ mod coord_tests {
mod budget_tests {
use super::*;
+ #[test]
+ fn application_attributes_wake_once_per_pid() {
+ assert!(first_application_walk(u32::MAX));
+ assert!(!first_application_walk(u32::MAX));
+ assert!(first_application_walk(u32::MAX - 1));
+ assert!(!first_application_walk(u32::MAX - 1));
+ }
+
#[test]
fn focus_log_tracks_latest_focused_object_per_bus_and_clears_on_blur() {
let bus = ":9.test-focus-log";