use crate::dll::{NativeCall, NativeFailure, NativeResult};
use alloc::string::{String, ToString};
use alloc::vec::Vec;
#[derive(Debug, Clone, PartialEq)]
pub enum WindowAnswer {
Active,
NotActive,
Absent,
Unknown(String),
}
pub trait Keyboard {
fn type_text(&mut self, text: &str) -> Result<String, String>;
fn press_key(&mut self, name: &str, modifiers: &[String]) -> Result<String, String>;
fn key_down(&mut self, _name: &str) -> Result<String, String> {
Err("this desktop cannot hold a key down".to_string())
}
fn key_up(&mut self, _name: &str) -> Result<String, String> {
Err("this desktop cannot hold a key down".to_string())
}
fn key_is_down(&mut self, _name: &str) -> Result<bool, String> {
Err("this desktop cannot tell which keys are down".to_string())
}
fn keys_down(&mut self) -> Result<Vec<String>, String> {
Err("this desktop cannot tell which keys are down".to_string())
}
fn lock_light(&mut self, _name: &str) -> Result<Option<bool>, String> {
Err("this desktop cannot tell the state of a lock light".to_string())
}
fn set_lock_light(&mut self, _name: &str, _on: bool) -> Result<bool, String> {
Err("this desktop cannot set a lock light".to_string())
}
fn set_lock(&mut self, _lock: &str, _on: bool) -> Result<(), String> {
Err("this desktop cannot change the state of the lock keys".to_string())
}
fn lock_is_on(&mut self, _lock: &str) -> Result<bool, String> {
Err("this desktop cannot read the state of the lock keys".to_string())
}
fn keyboard_layout_name(&mut self) -> Result<String, String> {
Err("this desktop cannot say the keyboard layout".to_string())
}
}
pub trait Pointer {
fn cursor_shape(&mut self) -> Result<String, String> {
Err("this desktop cannot tell the shape of the cursor".to_string())
}
fn click(&mut self, x: i64, y: i64, button: &str, count: u32) -> Result<String, String>;
fn mouse_down(
&mut self,
_x: Option<i64>,
_y: Option<i64>,
_button: &str,
) -> Result<String, String> {
Err("this desktop cannot hold a mouse button down".to_string())
}
fn mouse_up(
&mut self,
_x: Option<i64>,
_y: Option<i64>,
_button: &str,
) -> Result<String, String> {
Err("this desktop cannot hold a mouse button down".to_string())
}
fn move_pointer(&mut self, _x: i64, _y: i64) -> Result<String, String> {
Err("this desktop cannot move the pointer".to_string())
}
fn mouse_position(&mut self) -> Result<(i64, i64), String> {
Err("this desktop cannot tell where the pointer is".to_string())
}
fn set_mouse_speed(&mut self, _speed: i64) -> Result<String, String> {
Err("this desktop cannot change the speed of the pointer".to_string())
}
fn set_mouse_delay(&mut self, _delay: i64) -> Result<String, String> {
Err("this desktop cannot change the delay of the pointer".to_string())
}
fn clip_cursor(&mut self, _rect: Option<(i64, i64, i64, i64)>) -> Result<(), String> {
Err("this desktop cannot confine the pointer".to_string())
}
}
pub trait Screen {
fn capture(
&mut self,
x: i64,
y: i64,
width: i64,
height: i64,
filename: &str,
) -> Result<String, String>;
fn pixel(&mut self, x: i64, y: i64) -> Result<String, String>;
fn gui_controls(&mut self) -> Result<String, String> {
Err("this desktop cannot list the controls of the window of the script".to_string())
}
fn gui_all_text(&mut self) -> Result<String, String> {
Err("this desktop cannot read the text of the window of the script".to_string())
}
fn gui_opacity(&mut self, _setting: Option<i64>) -> Result<i64, String> {
Err("this desktop cannot read the opacity of the window of the script".to_string())
}
fn gui_paste(&mut self, _number: u64, _text: &str) -> Result<(), String> {
Err("this desktop cannot put a text into a control of the script".to_string())
}
fn gui_checked(&mut self, _number: u64, _setting: Option<bool>) -> Result<i64, String> {
Err("this desktop cannot read the tick of a check box of the script".to_string())
}
fn screen_scale(&mut self) -> Result<i64, String> {
Err("this desktop does not know the scale of the output".to_string())
}
fn screen_size(&mut self) -> Result<(i64, i64), String> {
Err("this desktop cannot tell how big the screen is".to_string())
}
fn tooltip_show(&mut self, _text: &str, _x: i64, _y: i64) -> Result<i64, String> {
Err("this desktop cannot show a tooltip".to_string())
}
fn window_move(&mut self, _x: i64, _y: i64, _width: i64, _height: i64) -> Result<(), String> {
Err("this desktop cannot move the window of the script".to_string())
}
fn monitors(&mut self) -> Result<Vec<Monitor>, String> {
Err("this desktop cannot list the monitors".to_string())
}
fn pixel_search(
&mut self,
_x1: i64,
_y1: i64,
_x2: i64,
_y2: i64,
_colour: &str,
) -> Result<Option<(i64, i64)>, String> {
Err("this desktop cannot search the screen for a colour".to_string())
}
fn monitor_work_area(
&mut self,
_monitor: usize,
) -> Result<Option<(i64, i64, i64, i64)>, String> {
Err("this desktop cannot say the work area of its monitors".to_string())
}
fn primary_monitor(&mut self) -> Result<usize, String> {
Err("this desktop cannot say which monitor is the primary one".to_string())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TitleMatch {
Starts,
Contains,
Exact,
Pattern,
}
impl TitleMatch {
pub fn matches(self, title: &str, wanted: &str) -> Result<bool, String> {
match self {
TitleMatch::Starts => Ok(title.starts_with(wanted)),
TitleMatch::Contains => Ok(title.contains(wanted)),
TitleMatch::Exact => Ok(title == wanted),
TitleMatch::Pattern => {
let (pattern, ignore_case) = match wanted.strip_prefix("i)") {
Some(rest) => (rest, true),
None => (wanted, false),
};
let pattern = if ignore_case {
alloc::format!("(?i){pattern}")
} else {
pattern.to_string()
};
let regex = crate::regex::Regex::new(&pattern)?;
Ok(regex.find(title)?.is_some())
}
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct WindowRef {
pub id: String,
pub class: String,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct WindowGeometry {
pub x: i64,
pub y: i64,
pub width: i64,
pub height: i64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WaitFor {
Present,
Active,
NotActive,
Close,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct DriveSpace {
pub free: i64,
pub capacity: i64,
pub filesystem: String,
pub kind: String,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Monitor {
pub name: String,
pub left: i64,
pub top: i64,
pub right: i64,
pub bottom: i64,
pub scale: i64,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ControlAnswer {
Found(String),
NoSuchWindow,
NoSuchControl,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ControlFlag {
Yes,
No,
NoSuchWindow,
NoSuchControl,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ControlEdit {
Done,
NoSuchWindow,
NoSuchControl,
}
pub trait Windows {
fn window_active(&mut self, _title: &str, _mode: TitleMatch) -> Result<WindowAnswer, String> {
Err("this desktop cannot tell which window is active".to_string())
}
fn window_exists(&mut self, _title: &str, _mode: TitleMatch) -> Result<WindowAnswer, String> {
Err("this desktop cannot list the windows".to_string())
}
fn active_window_title(&mut self) -> Result<Option<String>, String> {
Err("this desktop cannot tell which window is active".to_string())
}
fn matching_windows(
&mut self,
_title: &str,
_mode: TitleMatch,
) -> Result<Vec<WindowRef>, String> {
Err("this desktop cannot list the windows".to_string())
}
fn window_geometry(
&mut self,
_title: &str,
_mode: TitleMatch,
) -> Result<Option<WindowGeometry>, String> {
Err("this desktop cannot tell where a window is".to_string())
}
fn window_min_max(&mut self, _title: &str, _mode: TitleMatch) -> Result<Option<i64>, String> {
Err("this desktop cannot tell whether a window is maximized".to_string())
}
fn window_wait(
&mut self,
_title: &str,
_mode: TitleMatch,
_what: WaitFor,
_timeout_ms: u64,
) -> Result<Option<String>, String> {
Err("this desktop cannot wait for a window".to_string())
}
fn control_text(&mut self, _control: &str, _title: &str) -> Result<ControlAnswer, String> {
Err("this desktop cannot read the controls of a window".to_string())
}
fn control_visible(&mut self, _control: &str, _title: &str) -> Result<ControlFlag, String> {
Err("this desktop cannot read the controls of a window".to_string())
}
fn control_enabled(&mut self, _control: &str, _title: &str) -> Result<ControlFlag, String> {
Err("this desktop cannot read the controls of a window".to_string())
}
fn control_set_text(
&mut self,
_control: &str,
_title: &str,
_text: &str,
) -> Result<ControlEdit, String> {
Err("this desktop cannot write to the controls of a window".to_string())
}
fn control_click(&mut self, _control: &str, _title: &str) -> Result<ControlEdit, String> {
Err("this desktop cannot click the controls of a window".to_string())
}
fn control_focus(&mut self, _control: &str, _title: &str) -> Result<ControlEdit, String> {
Err("this desktop cannot focus the controls of a window".to_string())
}
fn control_send_text(
&mut self,
_control: &str,
_title: &str,
_text: &str,
) -> Result<ControlEdit, String> {
Err("this desktop cannot type into the controls of a window".to_string())
}
fn window_pid(&mut self, _title: &str) -> Result<Option<i64>, String> {
Err("this desktop cannot say the process of a window".to_string())
}
fn gui_is_open(&mut self) -> bool {
false
}
fn gui_open(&mut self, _title: &str) -> Result<u64, String> {
Err("this desktop cannot make a window of the script".to_string())
}
fn gui_add(&mut self, _handle: u64, _kind: &str, _text: &str) -> Result<(u64, String), String> {
Err("this desktop cannot add a control to a window of the script".to_string())
}
fn gui_combo_items(&mut self, _number: u64) -> Result<String, String> {
Err("this desktop cannot read the items of a list-shaped control".to_string())
}
fn gui_combo_add(&mut self, _number: u64, _text: &str) -> Result<(), String> {
Err("this desktop cannot add an item to a list-shaped control".to_string())
}
fn gui_combo_select(
&mut self,
_number: u64,
_wanted: &str,
_by_text: bool,
) -> Result<i64, String> {
Err("this desktop cannot choose an item of a list-shaped control".to_string())
}
fn gui_combo_choice(&mut self, _number: u64) -> Result<(i64, String), String> {
Err("this desktop cannot read the choice of a list-shaped control".to_string())
}
fn gui_combo_delete(&mut self, _number: u64, _index: &str) -> Result<(), String> {
Err("this desktop cannot remove an item of a list-shaped control".to_string())
}
fn gui_combo_find(&mut self, _number: u64, _text: &str) -> Result<i64, String> {
Err("this desktop cannot find an item of a list-shaped control".to_string())
}
fn gui_combo_dropdown(&mut self, _number: u64, _show: bool) -> Result<(), String> {
Err("this desktop cannot open the pop-up of a list-shaped control".to_string())
}
fn gui_status_text(&mut self) -> Result<String, String> {
Err("this desktop cannot read the text of a status bar".to_string())
}
fn gui_list_add(&mut self, _number: u64, _cells: &[String]) -> Result<i64, String> {
Err("this desktop cannot add a row to a list view".to_string())
}
fn gui_list_count(&mut self, _number: u64) -> Result<i64, String> {
Err("this desktop cannot count the rows of a list view".to_string())
}
fn gui_list_text(&mut self, _number: u64, _row: i64, _col: i64) -> Result<String, String> {
Err("this desktop cannot read a cell of a list view".to_string())
}
fn gui_list_content(&mut self, _number: u64, _selected: bool) -> Result<String, String> {
Err("this desktop cannot read the content of a list view".to_string())
}
fn gui_list_modify(
&mut self,
_number: u64,
_row: i64,
_cells: &[String],
) -> Result<i64, String> {
Err("this desktop cannot change a row of a list view".to_string())
}
fn gui_list_next(&mut self, _number: u64, _start: i64) -> Result<i64, String> {
Err("this desktop cannot read the next row of a list view".to_string())
}
fn gui_tree_add(
&mut self,
_number: u64,
_text: &str,
_parent: i64,
_options: &str,
) -> Result<i64, String> {
Err("this desktop cannot add an item to a tree view".to_string())
}
fn gui_tree_count(&mut self, _number: u64) -> Result<i64, String> {
Err("this desktop cannot count the items of a tree view".to_string())
}
fn gui_tree_text(&mut self, _number: u64, _item: i64) -> Result<String, String> {
Err("this desktop cannot read the text of an item of a tree view".to_string())
}
fn gui_tree_relation(
&mut self,
_number: u64,
_item: i64,
_relation: &str,
) -> Result<i64, String> {
Err("this desktop cannot walk a tree view".to_string())
}
fn gui_tree_selection(&mut self, _number: u64) -> Result<i64, String> {
Err("this desktop cannot read the selection of a tree view".to_string())
}
fn gui_tree_modify(&mut self, _number: u64, _item: i64, _options: &str) -> Result<i64, String> {
Err("this desktop cannot change an item of a tree view".to_string())
}
fn gui_tree_delete(&mut self, _number: u64, _item: i64) -> Result<i64, String> {
Err("this desktop cannot delete an item of a tree view".to_string())
}
fn gui_second_value(&mut self, _number: u64, _setting: Option<&str>) -> Result<String, String> {
Err("this desktop has no second text slot for a control".to_string())
}
fn gui_control_pos(&mut self, _number: u64) -> Result<(i64, i64, i64, i64), String> {
Err("this desktop cannot say where a control of the window is".to_string())
}
fn gui_menu_bar(&mut self, _json: &str) -> Result<(), String> {
Err("this desktop cannot show a menu bar on the window of the script".to_string())
}
fn gui_caret(&mut self) -> Result<Option<(i64, i64)>, String> {
Err("this desktop cannot find the caret of the window".to_string())
}
fn gui_show(&mut self, _handle: u64) -> Result<(), String> {
Err("this desktop cannot show a window of the script".to_string())
}
fn gui_destroy(&mut self, _handle: u64) -> Result<(), String> {
Err("this desktop cannot take away a window of the script".to_string())
}
fn gui_value(&mut self, _number: u64, _setting: Option<&str>) -> Result<String, String> {
Err("this desktop cannot read the text of a control of the script".to_string())
}
fn gui_flag(
&mut self,
_number: u64,
_name: &str,
_setting: Option<bool>,
) -> Result<i64, String> {
Err("this desktop cannot read a flag of a control of the script".to_string())
}
fn gui_control_state(&mut self, _classnn: &str, _what: &str, _on: bool) -> Result<(), String> {
Err("this desktop cannot set a state of a control of the script".to_string())
}
fn gui_visibility(&mut self, _classnn: &str, _on: bool) -> Result<(), String> {
Err("this desktop cannot show or hide a control of the script".to_string())
}
fn gui_number_named(&mut self, _classnn: &str) -> Result<i64, String> {
Err("this desktop cannot find a control of the script by its name".to_string())
}
fn gui_focused(&mut self) -> Result<String, String> {
Err("this desktop cannot read the focus of a control of the script".to_string())
}
fn gui_selection(&mut self, _number: u64) -> Result<String, String> {
Err("this desktop cannot read the selection of a control of the script".to_string())
}
fn gui_cursor(&mut self, _number: u64) -> Result<i64, String> {
Err("this desktop cannot read the cursor of a control of the script".to_string())
}
fn gui_line_count(&mut self, _number: u64) -> Result<i64, String> {
Err("this desktop cannot count the lines of a control of the script".to_string())
}
fn gui_option(&mut self, _name: &str, _on: bool) -> Result<(), String> {
Err("this desktop cannot set an option of the window of the script".to_string())
}
fn gui_hide(&mut self) -> Result<(), String> {
Err("this desktop cannot hide the window of the script".to_string())
}
fn gui_focus(&mut self, _number: u64) -> Result<(), String> {
Err("this desktop cannot put the focus on a control of the script".to_string())
}
fn gui_size(&mut self, _number: u64, _width: i64, _height: i64) -> Result<(), String> {
Err("this desktop cannot size a control of the script".to_string())
}
fn gui_events(&mut self) -> Result<Vec<String>, String> {
Ok(Vec::new())
}
fn gui_title(&mut self, _handle: u64, _setting: Option<&str>) -> Result<String, String> {
Err("this desktop cannot say the title of a window of the script".to_string())
}
fn window_capabilities(&mut self) -> Vec<String> {
Vec::new()
}
fn window_enabled(&mut self, _window: &WindowInfo) -> Result<Option<bool>, String> {
Err("this desktop cannot say whether a window is enabled".to_string())
}
fn set_always_on_top(&mut self, _window: &WindowInfo, _on: bool) -> Result<(), String> {
Err("this desktop cannot put a window above the others".to_string())
}
fn always_on_top(&mut self, _window: &WindowInfo) -> Result<Option<bool>, String> {
Err("this desktop cannot say whether a window is above the others".to_string())
}
fn windows(&mut self) -> Result<Vec<WindowInfo>, String> {
Err("this desktop cannot list the windows".to_string())
}
fn the_window_at(&mut self, _x: i64, _y: i64) -> Result<Option<i64>, String> {
Err("this desktop cannot say which window is at a point".to_string())
}
}
pub trait Processes {
fn run(&mut self, command: &str, window: &str) -> Result<(i32, String, String), String>;
fn launch(&mut self, _command: &str, _working_dir: &str) -> Result<u32, String> {
Err("this desktop cannot launch a program".to_string())
}
fn run_and_wait(
&mut self,
_command: &str,
_working_dir: &str,
) -> Result<(u32, i32, String, String), String> {
Err("this desktop cannot launch a program".to_string())
}
fn env_get(&mut self, _name: &str) -> Result<Option<String>, String> {
Err("this desktop cannot read the environment".to_string())
}
fn env_set(&mut self, _name: &str, _value: &str) -> Result<String, String> {
Err("this desktop cannot write the environment".to_string())
}
fn process_exist(&mut self, _which: Option<&str>) -> Result<u32, String> {
Err("this desktop cannot read the processes of the machine".to_string())
}
fn process_name(&mut self, _which: Option<&str>) -> Result<Option<String>, String> {
Err("this desktop cannot read the processes of the machine".to_string())
}
fn process_path(&mut self, _which: Option<&str>) -> Result<Option<String>, String> {
Err("this desktop cannot read the processes of the machine".to_string())
}
fn process_parent(&mut self, _which: Option<&str>) -> Result<u32, String> {
Err("this desktop cannot read the processes of the machine".to_string())
}
fn process_close(&mut self, _which: &str) -> Result<u32, String> {
Err("this desktop cannot close a process of the machine".to_string())
}
fn process_wait(&mut self, _which: &str, _timeout: Option<f64>) -> Result<u32, String> {
Err("this desktop cannot wait for a process of the machine".to_string())
}
fn process_wait_close(&mut self, _which: &str, _timeout: Option<f64>) -> Result<u32, String> {
Err("this desktop cannot wait for a process of the machine".to_string())
}
fn process_set_priority(
&mut self,
_priority: &str,
_which: Option<&str>,
) -> Result<Option<u32>, String> {
Err("this desktop cannot set the priority of a process".to_string())
}
fn kill_a_process(&mut self, _pid: u32) -> Result<(), String> {
Err("this desktop cannot kill a process".to_string())
}
fn the_state_of_a_process(&mut self, _pid: u32) -> Result<Option<ProcessState>, String> {
Err("this desktop cannot say the state of a process".to_string())
}
fn run_with_stdin(
&mut self,
_program: &str,
_arguments: &[String],
_standard_input: &str,
_working_dir: &str,
) -> Result<(u32, i32, String, String), String> {
Err("this desktop cannot launch a program".to_string())
}
fn launch_with_stdin(
&mut self,
_program: &str,
_arguments: &[String],
_standard_input: &str,
_working_dir: &str,
) -> Result<u32, String> {
Err("this desktop cannot launch a program".to_string())
}
}
pub trait Files {
fn create_shortcut(
&mut self,
_target: &str,
_shortcut: &str,
_working_directory: &str,
_arguments: &str,
_description: &str,
_icon: &str,
) -> Result<(), String> {
Err("this desktop cannot create a shortcut".to_string())
}
fn empty_the_trash(&mut self) -> Result<(), String> {
Err("this desktop cannot empty the trash".to_string())
}
fn recycle_a_file(&mut self, _path: &str) -> Result<(), String> {
Err("this desktop cannot put a file in the trash".to_string())
}
fn read_shortcut(
&mut self,
_shortcut: &str,
) -> Result<(String, String, String, String, String), String> {
Err("this desktop cannot read a shortcut".to_string())
}
fn set_working_directory(&mut self, _directory: &str) -> Result<String, String> {
Err("this desktop cannot change the working directory".to_string())
}
fn list_files(
&mut self,
_folder: &str,
_pattern: &str,
_mode: &str,
) -> Result<Vec<String>, String> {
Err("this desktop cannot list the files of a directory".to_string())
}
fn initial_working_directory(&mut self) -> Result<String, String> {
Err("this desktop cannot say where the run started".to_string())
}
fn working_directory(&mut self) -> Result<String, String> {
Err("this desktop cannot tell where the script runs".to_string())
}
fn read_file(&mut self, _path: &str) -> Result<Vec<String>, String> {
Err("this desktop cannot read a file".to_string())
}
fn read_the_bytes_of_a_file(&mut self, _path: &str) -> Result<Vec<u8>, String> {
Err("this desktop cannot read a file".to_string())
}
fn canonical_path(&mut self, _path: &str) -> Result<String, String> {
Err("this desktop cannot write the canonical form of a path".to_string())
}
fn write_file(&mut self, _path: &str, _text: &str) -> Result<String, String> {
Err("this desktop cannot write a file".to_string())
}
fn append_file(&mut self, _path: &str, _bytes: &[u8], _mark: &[u8]) -> Result<String, String> {
Err("this desktop cannot write a file".to_string())
}
fn attributes_of_the_pattern(
&mut self,
_pattern: &str,
_mode: &str,
) -> Result<Vec<String>, String> {
Err("this desktop cannot look for a file".to_string())
}
fn delete_file(&mut self, _path: &str) -> Result<String, String> {
Err("this desktop cannot delete a file".to_string())
}
fn create_dir(&mut self, _path: &str) -> Result<String, String> {
Err("this desktop cannot make a directory".to_string())
}
fn dir_delete(&mut self, _path: &str, _recurse: bool) -> Result<String, String> {
Err("this desktop cannot delete a directory".to_string())
}
fn open_file(&mut self, _path: &str, _mode: &str) -> Result<i64, String> {
Err("this desktop cannot open a file".to_string())
}
fn read_file_at(&mut self, _handle: i64, _pos: i64, _count: i64) -> Result<Vec<u8>, String> {
Err("this desktop cannot read a file".to_string())
}
fn write_file_at(&mut self, _handle: i64, _pos: i64, _bytes: &[u8]) -> Result<usize, String> {
Err("this desktop cannot write a file".to_string())
}
fn file_size(&mut self, _handle: i64) -> Result<i64, String> {
Err("this desktop cannot tell how big a file is".to_string())
}
fn the_size_of_a_file(&mut self, _path: &str) -> Result<i64, String> {
Err("this desktop cannot tell how big a file is".to_string())
}
fn close_file(&mut self, _handle: i64) -> Result<(), String> {
Err("this desktop cannot close a file".to_string())
}
fn copy_file(&mut self, _from: &str, _to: &str, _overwrite: bool) -> Result<String, String> {
Err("this desktop cannot copy a file".to_string())
}
fn move_file(&mut self, _from: &str, _to: &str, _overwrite: bool) -> Result<String, String> {
Err("this desktop cannot move a file".to_string())
}
fn copy_dir(&mut self, _from: &str, _to: &str, _overwrite: bool) -> Result<String, String> {
Err("this desktop cannot copy a folder".to_string())
}
fn move_dir(&mut self, _from: &str, _to: &str, _overwrite: bool) -> Result<String, String> {
Err("this desktop cannot move a folder".to_string())
}
fn file_attributes(&mut self, _path: &str) -> Result<Vec<String>, String> {
Err("this desktop cannot read the attributes of a file".to_string())
}
fn set_file_attributes(
&mut self,
_path: &str,
_attributes: &[String],
) -> Result<String, String> {
Err("this desktop cannot change the attributes of a file".to_string())
}
fn file_times(&mut self, _path: &str) -> Result<(i64, i64, i64), String> {
Err("this desktop cannot read the times of a file".to_string())
}
fn set_file_times(
&mut self,
_path: &str,
_created: Option<i64>,
_modified: Option<i64>,
_accessed: Option<i64>,
) -> Result<String, String> {
Err("this desktop cannot change the times of a file".to_string())
}
fn ini_read(
&mut self,
_path: &str,
_section: &str,
_key: &str,
_default: &str,
) -> Result<String, String> {
Err("this desktop cannot read an ini file".to_string())
}
fn ini_write(
&mut self,
_path: &str,
_section: &str,
_key: &str,
_value: &str,
) -> Result<String, String> {
Err("this desktop cannot write an ini file".to_string())
}
fn ini_delete(&mut self, _path: &str, _section: &str, _key: &str) -> Result<String, String> {
Err("this desktop cannot write an ini file".to_string())
}
fn empty_trash(&mut self, _drive: Option<&str>) -> Result<(), String> {
Err("this desktop has no trash to empty".to_string())
}
fn recycle(&mut self, _pattern: &str) -> Result<(), String> {
Err("this desktop has no trash to recycle a file into".to_string())
}
fn create_temp_file(&mut self) -> Result<String, String> {
Err("this desktop cannot make a temporary file".to_string())
}
fn full_path(&mut self, _path: &str) -> Result<String, String> {
Err("this desktop cannot say the full path of a file".to_string())
}
}
pub trait Clipboard {
fn clipboard_read(&mut self) -> Result<String, String> {
Err("this desktop cannot read the clipboard".to_string())
}
fn clipboard_write(&mut self, _text: &str) -> Result<String, String> {
Err("this desktop cannot write the clipboard".to_string())
}
}
pub trait Timers {
fn takes_over_timers(&mut self) -> bool {
false
}
}
pub trait Hotkeys {
fn register_hotkey(&mut self, _name: &str) -> Result<String, String> {
Err("this desktop cannot register a hotkey".to_string())
}
fn unregister_hotkey(&mut self, _name: &str) -> Result<String, String> {
Err("this desktop cannot register a hotkey".to_string())
}
fn hotkeys(&mut self) -> Result<Vec<String>, String> {
Err("this desktop cannot list the hotkeys".to_string())
}
fn fired_hotkey(&mut self) -> Result<Option<String>, String> {
Err("this desktop cannot watch the keyboard".to_string())
}
}
pub trait Native {
fn call_native(&mut self, _call: &mut NativeCall) -> Result<NativeResult, NativeFailure> {
Err(NativeFailure::invalid(
"this desktop cannot make a native call.",
))
}
}
pub trait Pictures {
fn load_picture(
&mut self,
_filename: &str,
_options: &PictureOptions,
) -> Result<Option<u32>, String> {
Err("the picture is read by the desktop, and this desktop does not read the images of the machine.".to_string())
}
fn image_search(
&mut self,
_x1: i64,
_y1: i64,
_x2: i64,
_y2: i64,
_image: &Image,
_options: &ImageOptions,
) -> Result<ImageSearch, String> {
Err("the search of a picture is made by the desktop, and this desktop does not read the images of the machine.".to_string())
}
}
pub trait Network {
fn download(&mut self, _url: &str, _file: &str) -> Result<String, String> {
Err(
"the download is made by the desktop, and this desktop does not reach the network."
.to_string(),
)
}
fn ip_addresses(&mut self) -> Result<Vec<String>, String> {
Err("this desktop cannot list the addresses of its interfaces.".to_string())
}
fn send_mail(&mut self, _message: &MailMessage) -> Result<(), String> {
Err("this desktop cannot send mail".to_string())
}
}
#[derive(Clone, Debug, Default)]
pub struct PictureOptions {
pub width: Option<i64>,
pub height: Option<i64>,
pub icon: Option<i64>,
}
#[derive(Clone, Debug, Default)]
pub struct ImageOptions {
pub variation: i64,
pub width: Option<i64>,
pub height: Option<i64>,
pub transparent: Option<String>,
}
#[derive(Clone, Debug)]
pub enum Image {
File(String),
Loaded(u32),
}
#[derive(Clone, Debug)]
pub enum ImageSearch {
NotFound,
Found(i64, i64),
NotLoadable,
}
pub trait Sound {
fn sound_device_names(&mut self) -> Result<(String, String), String> {
Err("this desktop cannot tell the names of the sound devices".to_string())
}
fn sound_device_named(&mut self, _device: &str) -> Result<Option<String>, String> {
Err("this desktop cannot tell the names of the sound devices".to_string())
}
fn sound_volume(&mut self, _device: &str) -> Result<f64, String> {
Err("this desktop cannot say the volume of a device".to_string())
}
fn sound_set_volume(&mut self, _device: &str, _volume: f64) -> Result<(), String> {
Err("this desktop cannot set the volume of a device".to_string())
}
fn sound_muted(&mut self, _device: &str) -> Result<bool, String> {
Err("this desktop cannot say whether a device is muted".to_string())
}
fn sound_set_muted(&mut self, _device: &str, _muted: bool) -> Result<(), String> {
Err("this desktop cannot mute a device".to_string())
}
fn sound_play(&mut self, _path: &str) -> Result<String, String> {
Err("this desktop cannot play a sound".to_string())
}
fn sound_beep(&mut self, _frequency: f64, _duration_ms: u64) -> Result<String, String> {
Err("this desktop cannot play a tone".to_string())
}
}
pub trait Machine {
fn user_name(&mut self) -> Result<String, String> {
Err("this desktop cannot say the name of the user".to_string())
}
fn computer_name(&mut self) -> Result<String, String> {
Err("this desktop cannot say the name of the computer".to_string())
}
fn shell(&mut self) -> Result<String, String> {
Err("this desktop cannot say the shell of the session".to_string())
}
fn folders(&mut self) -> Result<Folders, String> {
Err("this desktop cannot say the folders of the machine".to_string())
}
fn os_version(&mut self) -> Result<String, String> {
Err("this desktop cannot say the version of the operating system".to_string())
}
fn language(&mut self) -> Result<String, String> {
Err("this desktop cannot say the language of the session".to_string())
}
fn is_admin(&mut self) -> Result<bool, String> {
Err("this desktop cannot say whether the script is elevated".to_string())
}
fn executable(&mut self) -> Result<String, String> {
Err("this desktop cannot tell the path of the interpreter".to_string())
}
fn drive_space(&mut self, _path: &str) -> Result<Option<DriveSpace>, String> {
Err("this desktop cannot tell the space of a drive".to_string())
}
fn registry_value(
&mut self,
_key: &str,
_name: &str,
) -> Result<Option<(String, String)>, String> {
Err("this desktop cannot read the registry of the machine".to_string())
}
fn registry_write(
&mut self,
_key: &str,
_name: &str,
_kind: &str,
_value: &str,
) -> Result<(), String> {
Err("this desktop cannot write the registry of the machine".to_string())
}
fn registry_delete(&mut self, _key: &str, _name: &str) -> Result<(), String> {
Err("this desktop cannot remove a value of the registry".to_string())
}
fn registry_delete_key(&mut self, _key: &str) -> Result<(), String> {
Err("this desktop cannot remove a key of the registry".to_string())
}
fn registry_create_key(&mut self, _key: &str) -> Result<(), String> {
Err("this desktop cannot make a key of the registry".to_string())
}
fn windows_directory(&mut self) -> Result<String, String> {
Err("this desktop cannot tell the directory of the Windows of the machine".to_string())
}
fn program_files(&mut self) -> Result<String, String> {
Err("this desktop cannot tell the directory of the programs of the machine".to_string())
}
fn tray_set_icon(&mut self, _name: &str) -> Result<(), String> {
Err("this desktop has no tray to put the icon of the script in".to_string())
}
fn drive_label(&mut self, _path: &str) -> Result<Option<String>, String> {
Err("this desktop cannot tell the label of a drive".to_string())
}
fn drive_serial(&mut self, _path: &str) -> Result<Option<String>, String> {
Err("this desktop cannot tell the serial of a drive".to_string())
}
fn drive_list(&mut self) -> Result<Vec<String>, String> {
Err("this desktop cannot list the drives".to_string())
}
fn drive_status_cd(&mut self, _path: &str) -> Result<Option<String>, String> {
Err("this desktop cannot tell the status of a CD drive".to_string())
}
fn drive_eject(&mut self, _path: &str) -> Result<(), String> {
Err("this desktop cannot eject a drive".to_string())
}
fn drive_lock(&mut self, _path: &str) -> Result<(), String> {
Err("this desktop cannot lock a drive".to_string())
}
fn drive_unlock(&mut self, _path: &str) -> Result<(), String> {
Err("this desktop cannot unlock a drive".to_string())
}
fn drive_retract(&mut self, _path: &str) -> Result<(), String> {
Err("this desktop cannot spin a drive down".to_string())
}
fn drive_set_label(&mut self, _path: &str, _label: &str) -> Result<(), String> {
Err("this desktop cannot write the label of a drive".to_string())
}
fn idle_times(&mut self) -> Result<Idle, String> {
Err("this desktop cannot say how long the session has been idle".to_string())
}
fn drive_status(&mut self, _path: &str) -> Result<Option<String>, String> {
Err("this desktop cannot say what state a drive is in".to_string())
}
fn drive_type(&mut self, _path: &str) -> Result<Option<String>, String> {
Err("this desktop cannot say what kind a drive is".to_string())
}
fn drive(&mut self, _path: &str) -> Result<Option<Drive>, String> {
Err("this desktop cannot say what a drive is".to_string())
}
fn output_debug(&mut self, _text: &str) -> Result<(), String> {
Err("this desktop has no debugger to write to".to_string())
}
fn the_current_thread_id(&mut self) -> Result<i64, String> {
Err("this desktop cannot say the thread it runs on".to_string())
}
}
pub trait Dialogs {
fn input_box(
&mut self,
_prompt: &str,
_title: &str,
_options: &InputOptions,
_default: &str,
) -> Result<InputAnswer, String> {
Err("this desktop cannot ask the user for a text".to_string())
}
fn file_select(
&mut self,
_options: &FileOptions,
_root: &str,
_title: &str,
_filter: &str,
) -> Result<FileAnswer, String> {
Err("this desktop cannot ask the user for a file".to_string())
}
fn dir_select(
&mut self,
_starting: &str,
_options: i64,
_prompt: &str,
) -> Result<String, String> {
Err("this desktop cannot ask the user for a folder".to_string())
}
fn notify(&mut self, _title: &str, _text: &str) -> Result<(), String> {
Err("this desktop cannot show a notification".to_string())
}
}
#[derive(Clone, Debug, Default)]
pub struct InputAnswer {
pub value: String,
pub result: String,
}
#[derive(Clone, Debug)]
pub enum FileAnswer {
One(String),
Many(Vec<String>),
}
#[derive(Clone, Debug, Default)]
pub struct InputOptions {
pub timeout: Option<f64>,
pub password: bool,
pub width: Option<i64>,
pub height: Option<i64>,
pub x: Option<i64>,
pub y: Option<i64>,
}
#[derive(Clone, Debug, Default)]
pub struct FileOptions {
pub flags: i64,
pub directory: bool,
pub multiple: bool,
pub save: bool,
}
#[derive(Clone, Debug, Default)]
pub struct Folders {
pub app_data: Option<String>,
pub app_data_common: Option<String>,
pub desktop: Option<String>,
pub desktop_common: Option<String>,
pub start_menu: Option<String>,
pub start_menu_common: Option<String>,
pub programs: Option<String>,
pub programs_common: Option<String>,
pub startup: Option<String>,
pub startup_common: Option<String>,
pub my_documents: Option<String>,
pub temp: Option<String>,
}
#[derive(Clone, Copy, Debug, Default)]
pub struct Idle {
pub any: u64,
pub physical: u64,
pub keyboard: u64,
pub mouse: u64,
}
pub trait Desktop:
Keyboard
+ Pointer
+ Screen
+ Windows
+ Processes
+ Files
+ Clipboard
+ Timers
+ Hotkeys
+ Native
+ Sound
+ Machine
+ Dialogs
+ Network
+ Pictures
{
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct WindowInfo {
pub id: i64,
pub title: String,
pub class: String,
pub active: bool,
}
#[derive(Debug, Clone)]
pub struct ProcessState {
pub has_exited: bool,
pub exit_code: Option<i32>,
pub exit_time: Option<String>,
}
pub struct MailMessage {
pub to: Vec<String>,
pub cc: Vec<String>,
pub bcc: Vec<String>,
pub subject: String,
pub body: String,
pub from: String,
pub reply_to: Option<String>,
pub attachments: Vec<String>,
pub headers: Vec<(String, String)>,
pub host: String,
pub port: u16,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Drive {
pub drive_type: String,
pub filesystem: String,
pub label: String,
pub serial: i64,
pub free_megabytes: i64,
pub capacity_megabytes: i64,
pub status: String,
}
impl Monitor {
pub fn width(&self) -> i64 {
self.right - self.left
}
pub fn height(&self) -> i64 {
self.bottom - self.top
}
}