#[cfg(target_os = "macos")]
mod macos;
use std::{fmt::Debug, sync::Arc};
use crate::{Application, ClickRequest, Element, Position, Rect, Role, Size, UIResult};
pub trait Backend: Debug {
#[must_use]
fn name(&self) -> &'static str;
#[must_use]
fn get_mouse_position(&self) -> UIResult<Position>;
fn set_mouse_position(&self, position: Position) -> UIResult<()>;
fn applications(&self, this: Arc<dyn Backend>) -> UIResult<Vec<Application>>;
fn windows(&self, application: &Application) -> UIResult<Vec<Element>>;
}
pub trait ElementBackend: Debug {
fn children(&self) -> UIResult<Vec<Element>>;
fn click(&self, request: ClickRequest) -> UIResult<()>;
fn description(&self) -> UIResult<String>;
fn rect(&self) -> UIResult<Rect>;
fn role(&self) -> UIResult<Role>;
fn title(&self) -> UIResult<String>;
fn url(&self) -> UIResult<String>;
fn position(&self) -> UIResult<Position> {
Ok(self.rect()?.position())
}
fn size(&self) -> UIResult<Size> {
Ok(self.rect()?.size())
}
}
pub(crate) fn create_backend() -> UIResult<Arc<dyn Backend>> {
#[cfg(target_os = "macos")]
{
return Ok(Arc::new(macos::create_macos_backend()?));
}
#[cfg(not(target_os = "macos"))]
Err(crate::UIErrorKind::PlatformNotSupported.into())
}