use anyhow::Result;
#[async_trait::async_trait]
pub trait DesktopSession: Send + Sync {
async fn activate_app(&self, bundle_id: &str) -> Result<String, String>;
async fn list_windows(&self, bundle_id: &str) -> Result<String, String>;
async fn close_window(&self, bundle_id: &str, window_idx: u32) -> Result<String, String>;
async fn get_main_window(&self, bundle_id: &str) -> Result<String, String>;
async fn screenshot_window(&self, bundle_id: &str) -> Result<String, String>;
async fn screenshot_region(&self, x: u32, y: u32, w: u32, h: u32) -> Result<String, String>;
async fn mouse_move(&self, x: u32, y: u32) -> Result<String, String>;
async fn mouse_click(&self, x: u32, y: u32) -> Result<String, String>;
async fn mouse_double_click(&self, x: u32, y: u32) -> Result<String, String>;
async fn mouse_drag(&self, x1: u32, y1: u32, x2: u32, y2: u32) -> Result<String, String>;
async fn mouse_scroll(&self, clicks: i32) -> Result<String, String>;
async fn key_press(&self, key: &str, modifiers: &[String]) -> Result<String, String>;
async fn clipboard_set(&self, text: &str) -> Result<String, String>;
async fn clipboard_get(&self) -> Result<String, String>;
async fn clipboard_set_file(&self, file_path: &str) -> Result<String, String>;
async fn clipboard_get_image(&self) -> Result<String, String>;
async fn mouse_right_click(&self, x: u32, y: u32) -> Result<String, String>;
async fn file_dialog_open(&self, title: &str, filters: &[String]) -> Result<String, String>;
}
pub fn create_session() -> Box<dyn DesktopSession> {
#[cfg(target_os = "macos")]
{
Box::new(native::NativeDesktopSession)
}
#[cfg(target_os = "windows")]
{
Box::new(native::NativeDesktopSession)
}
#[cfg(target_os = "linux")]
{
Box::new(native::NativeDesktopSession)
}
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))]
{
compile_error!("DesktopSession not supported on this platform")
}
}
mod native;