xa11y/
lib.rs

1//! xa11y — Cross-Platform Accessibility Client Library
2//!
3//! Provides a unified API for reading and interacting with accessibility trees
4//! across desktop platforms (macOS, Windows, Linux).
5//!
6//! # Quick Start
7//!
8//! ```no_run
9//! use xa11y::*;
10//!
11//! let provider = create_provider().expect("Failed to create provider");
12//! let status = provider.check_permissions().expect("Permission check failed");
13//!
14//! match status {
15//!     PermissionStatus::Granted => {
16//!         let tree = provider.get_app_tree(
17//!             &AppTarget::ByName("Safari".to_string()),
18//!             &QueryOptions::default(),
19//!         ).expect("Failed to get tree");
20//!
21//!         let buttons = tree.query("button").expect("Query failed");
22//!         println!("Found {} buttons", buttons.len());
23//!     }
24//!     PermissionStatus::Denied { instructions } => {
25//!         eprintln!("Accessibility not enabled: {}", instructions);
26//!     }
27//! }
28//! ```
29
30// Re-export all core types
31pub use xa11y_core::*;
32
33// Platform-specific provider creation
34
35/// Create a platform-appropriate accessibility provider.
36///
37/// Returns a boxed `Provider` trait object for the current platform.
38/// On unsupported platforms, returns a `Platform` error.
39pub fn create_provider() -> Result<Box<dyn Provider>> {
40    #[cfg(target_os = "macos")]
41    {
42        Ok(Box::new(xa11y_macos::MacOSProvider::new()?))
43    }
44
45    #[cfg(target_os = "windows")]
46    {
47        Ok(Box::new(xa11y_windows::WindowsProvider::new()?))
48    }
49
50    #[cfg(target_os = "linux")]
51    {
52        Ok(Box::new(xa11y_linux::LinuxProvider::new()?))
53    }
54
55    #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))]
56    {
57        Err(Error::Platform {
58            code: -1,
59            message: format!("Unsupported platform: {}", std::env::consts::OS),
60        })
61    }
62}
63
64/// Create a platform-appropriate event provider (supports subscribe/wait).
65///
66/// Returns a boxed `EventProvider` trait object for the current platform.
67/// EventProvider extends Provider with event subscription capabilities.
68pub fn create_event_provider() -> Result<Box<dyn EventProvider>> {
69    #[cfg(target_os = "macos")]
70    {
71        Ok(Box::new(xa11y_macos::MacOSProvider::new()?))
72    }
73
74    #[cfg(target_os = "windows")]
75    {
76        Ok(Box::new(xa11y_windows::WindowsProvider::new()?))
77    }
78
79    #[cfg(target_os = "linux")]
80    {
81        Ok(Box::new(xa11y_linux::LinuxProvider::new()?))
82    }
83
84    #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))]
85    {
86        Err(Error::Platform {
87            code: -1,
88            message: format!("Unsupported platform: {}", std::env::consts::OS),
89        })
90    }
91}