pub mod criteria;
use crate::dll::{NativeArg, NativeCall, NativeFailure, NativeResult, NativeType};
use crate::runtime::Value;
use alloc::string::{String, ToString};
use alloc::vec;
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())
}
fn key_in_layout(&mut self, _vk: u32, _name: &str, _layout: &str) -> Result<(u32, u32), String> {
Err("this desktop cannot resolve a key in a 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 mouse_wheel(
&mut self,
_x: Option<i64>,
_y: Option<i64>,
_direction: &str,
_amount: u32,
) -> Result<String, String> {
Err("this desktop cannot turn the wheel of the mouse".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_dpi(&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())
}
fn system_metric(&mut self, _metric: i32) -> Option<i64> {
None
}
}
#[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_exe(&mut self, _id: i64) -> String {
String::new()
}
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,
_excludes: &[String],
) -> 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 control_style(
&mut self,
_control: &str,
_title: &str,
_extended: bool,
) -> Result<i64, String> {
Err("this desktop cannot read the style of a control".to_string())
}
fn control_set_style(
&mut self,
_control: &str,
_title: &str,
_style: i64,
_extended: bool,
) -> Result<(), String> {
Err("this desktop cannot write the style of a control".to_string())
}
fn control_hwnds_of(&mut self, _window: i64) -> Result<Vec<i64>, String> {
Err("this desktop cannot list the controls of a window".to_string())
}
fn control_classnn_of(&mut self, _control: i64) -> Result<String, String> {
Err("this desktop cannot name a control by its handle".to_string())
}
fn control_style_of_hwnd(&mut self, _control: i64, _extended: bool) -> Result<i64, String> {
Err("this desktop cannot read the style of a control".to_string())
}
fn control_set_style_of_hwnd(
&mut self,
_control: i64,
_style: i64,
_extended: bool,
) -> Result<(), String> {
Err("this desktop cannot write the style of a control".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 window_style(&mut self, _title: &str, _extended: bool) -> Result<i64, String> {
Err("this desktop cannot read the style of a window".to_string())
}
fn window_set_style(
&mut self,
_title: &str,
_style: i64,
_extended: bool,
) -> Result<(), String> {
Err("this desktop cannot write the style of a window".to_string())
}
fn window_trans_color(&mut self, _title: &str) -> Result<String, String> {
Err("this desktop cannot read the transparent colour of a window".to_string())
}
fn window_set_trans_color(&mut self, _title: &str, _color: &str) -> Result<(), String> {
Err("this desktop cannot write the transparent colour of a window".to_string())
}
fn script_window(&mut self) -> Result<i64, String> {
Err("this desktop has no window of the script".to_string())
}
fn carries_the_gui(&mut self) -> bool {
false
}
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 menu_create(&mut self) -> Result<u64, String> {
Err("this desktop cannot make a menu".to_string())
}
fn menu_add(&mut self, _menu: u64, _name: &str, _callback: &str) -> Result<(), String> {
Err("this desktop cannot add an item to a menu".to_string())
}
fn menu_handle(&mut self, _menu: u64) -> Result<i64, String> {
Err("this desktop cannot give the handle of a menu".to_string())
}
fn menu_delete(&mut self, _menu: u64, _name: &str) -> Result<(), String> {
Err("this desktop cannot delete an item of a menu".to_string())
}
fn menu_rename(&mut self, _menu: u64, _name: &str, _new: &str) -> Result<(), String> {
Err("this desktop cannot rename an item of a menu".to_string())
}
fn menu_enable(&mut self, _menu: u64, _name: &str, _on: bool) -> Result<(), String> {
Err("this desktop cannot enable an item of a menu".to_string())
}
fn menu_check(&mut self, _menu: u64, _name: &str, _on: bool) -> Result<(), String> {
Err("this desktop cannot check an item of a menu".to_string())
}
fn menu_count(&mut self, _menu: u64) -> Result<i64, String> {
Err("this desktop cannot count the items of a menu".to_string())
}
fn menu_is_enabled(&mut self, _menu: u64, _name: &str) -> Result<bool, String> {
Err("this desktop cannot say whether an item of a menu is enabled".to_string())
}
fn menu_is_checked(&mut self, _menu: u64, _name: &str) -> Result<bool, String> {
Err("this desktop cannot say whether an item of a menu is checked".to_string())
}
fn menu_show(&mut self, _menu: u64) -> Result<Option<String>, String> {
Err("this desktop cannot show a menu".to_string())
}
fn menu_attach(&mut self, _menu: u64) -> Result<(), String> {
Err("this desktop cannot attach a menu to 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_classnn(&mut self, _number: u64) -> Result<String, String> {
Err("this desktop cannot name a control of the script".to_string())
}
fn gui_handle(&mut self, _number: u64) -> Result<i64, String> {
Err("this desktop has no handle for a control of the script".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 watch_a_message(&mut self, _number: i64) -> Result<(), String> {
Err("this desktop cannot watch a message of the window of the script".to_string())
}
fn post_a_message(
&mut self,
_window: i64,
_message: i64,
_wparam: i64,
_lparam: i64,
) -> Result<(), String> {
Err("this desktop cannot post a message to a window".to_string())
}
fn send_a_message(
&mut self,
_window: i64,
_message: i64,
_wparam: i64,
_lparam: i64,
) -> Result<i64, String> {
Err("this desktop cannot send a message to a window".to_string())
}
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 run_with_pid(
&mut self,
command: &str,
window: &str,
) -> Result<(i32, String, String, u32), String> {
let (code, stdout, stderr) = self.run(command, window)?;
Ok((code, stdout, stderr, 0))
}
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 open_with_the_default_program(&mut self, _path: &str) -> Result<(), String> {
Err("this desktop cannot open a file with the program of the machine".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())
}
fn clipboard_read_all(&mut self) -> Result<Vec<u8>, String> {
Err("this desktop cannot read the binary clipboard".to_string())
}
fn clipboard_write_all(&mut self, _data: &[u8]) -> Result<(), String> {
Err("this desktop cannot write the binary clipboard".to_string())
}
fn read_memory(&mut self, _address: i64, _size: i64) -> Result<Vec<u8>, String> {
Err("this desktop cannot read the memory of the process".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())
}
fn wait_for_event(&mut self, _timeout: u64) -> Result<bool, String> {
Err("this desktop cannot wait for an event".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.",
))
}
fn call_native_at(
&mut self,
_address: u64,
_call: &mut NativeCall,
) -> Result<NativeResult, NativeFailure> {
Err(NativeFailure::invalid(
"this desktop cannot make a native call.",
))
}
fn load_library(&mut self, _name: &str) -> Result<(), String> {
Err("this desktop cannot load a library.".to_string())
}
fn create_callback(
&mut self,
_func: &crate::runtime::Value,
_param_count: usize,
) -> Result<u64, String> {
Err("this desktop cannot create a native callback.".to_string())
}
fn free_callback(&mut self, _address: u64) {}
}
#[derive(Clone, Debug, PartialEq)]
pub enum ComAnswer {
Empty,
Number(f64),
Text(String),
Object { pointer: u64, kind: i64 },
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum MemberWhat {
Get,
Set,
Call,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ComObject {
pub pointer: u64,
pub kind: i64,
}
#[derive(Clone, Debug, PartialEq)]
pub enum ComValue {
Number(f64),
Text(String),
Pointer(u64),
}
#[derive(Clone, Debug, PartialEq)]
pub struct ComEvent {
pub name: String,
pub object: u64,
pub kind: i64,
pub arguments: Vec<ComValue>,
}
pub trait Com {
fn com_object_of_the_class(
&mut self,
_class: &str,
_interface: Option<&str>,
) -> Result<ComObject, String> {
Err(
"the COM objects are a thing of Windows, and this runtime does not carry them."
.to_string(),
)
}
fn com_object_of_the_running(&mut self, _class: &str) -> Result<ComObject, String> {
Err("(0x800401F3) Invalid class string".to_string())
}
fn com_object_of_the_name(&mut self, _name: &str) -> Result<ComObject, String> {
Err("(0x80070057) The parameter is incorrect.".to_string())
}
fn com_object_is_queried(
&mut self,
_object: &ComObject,
_interface: &str,
) -> Result<ComObject, String> {
Err(
"this platform has no COM: there is no object model for an interface to be asked of"
.to_string(),
)
}
fn com_type_of_the_object(
&mut self,
_object: &ComObject,
_what: &str,
) -> Result<String, String> {
Err(
"this platform has no COM: there is no object model for a class to be asked of"
.to_string(),
)
}
fn com_value_is_made(&mut self, _kind: i64, _value: ComValue) -> Result<ComObject, String> {
Err(
"the COM objects are a thing of Windows, and this runtime does not carry them."
.to_string(),
)
}
fn com_method_is_called(
&mut self,
_object: &ComObject,
_index: usize,
_arguments: &mut [NativeArg],
_returns: NativeType,
_failure_is_an_error: bool,
) -> Result<NativeResult, String> {
Err(
"this platform has no COM: there is no object model behind the call of a method"
.to_string(),
)
}
fn com_object_is_connected(
&mut self,
_object: &ComObject,
_prefix: &str,
) -> Result<(), String> {
Err(
"the events of a COM object are a sink that this runtime does not carry: the script cannot be called back by the machine."
.to_string(),
)
}
fn com_events_are_taken(&mut self, _wait_ms: u64) -> Vec<ComEvent> {
Vec::new()
}
fn com_member(
&mut self,
_object: &ComObject,
_what: MemberWhat,
_name: &str,
_arguments: &[ComValue],
) -> Result<ComAnswer, String> {
Err(
"this platform has no COM: there is no object model for a member to be asked of"
.to_string(),
)
}
}
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, _component: &str) -> Result<f64, String> {
Err("this desktop cannot say the volume of a device".to_string())
}
fn sound_set_volume(
&mut self,
_device: &str,
_component: &str,
_volume: f64,
) -> Result<(), String> {
Err("this desktop cannot set the volume of a device".to_string())
}
fn sound_muted(&mut self, _device: &str, _component: &str) -> Result<bool, String> {
Err("this desktop cannot say whether a device is muted".to_string())
}
fn sound_set_muted(
&mut self,
_device: &str,
_component: &str,
_muted: bool,
) -> Result<(), String> {
Err("this desktop cannot mute a device".to_string())
}
fn sound_interface_of_the_device(
&mut self,
_device: &str,
_interface: &str,
) -> Result<u64, String> {
Ok(0)
}
fn sound_play(&mut self, _path: &str) -> Result<String, String> {
Err("this desktop cannot play a sound".to_string())
}
fn sound_control(
&mut self,
_component: &str,
_control: &str,
_device: &str,
) -> Result<SoundControl, SoundFailure> {
Err(SoundFailure::NoControl)
}
fn sound_control_is_set(
&mut self,
_component: &str,
_control: &str,
_value: f64,
_device: &str,
) -> Result<(), SoundFailure> {
Err(SoundFailure::NoControl)
}
fn sound_beep(&mut self, _frequency: f64, _duration_ms: u64) -> Result<String, String> {
Err("this desktop cannot play a tone".to_string())
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum SoundControl {
Volume(f64),
Switch(bool),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SoundFailure {
NoComponent,
NoControl,
NoMixer,
NoSetting,
NoChange,
}
impl SoundFailure {
pub fn the_words_of_the_v2(&self) -> &'static str {
match self {
SoundFailure::NoComponent => "Component not found",
SoundFailure::NoControl => "Component doesn't support this control type",
SoundFailure::NoMixer => "Device not found",
SoundFailure::NoSetting => "Cannot get current setting",
SoundFailure::NoChange => "Cannot change setting",
}
}
pub fn the_words_of_the_v1(&self) -> &'static str {
match self {
SoundFailure::NoComponent => "Mixer Doesn't Support This Component Type",
SoundFailure::NoControl => "Component Doesn't Support This Control Type",
SoundFailure::NoMixer => "Can't Open Specified Mixer",
SoundFailure::NoSetting => "Can't Get Current Setting",
SoundFailure::NoChange => "Can't Change Setting",
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum ThreadValue {
Int(i64),
Float(f64),
Text(String),
Array(Vec<ThreadValue>),
}
impl ThreadValue {
pub fn to_value(&self) -> crate::runtime::Value {
match self {
ThreadValue::Int(number) => crate::runtime::Value::Int(*number),
ThreadValue::Float(number) => crate::runtime::Value::Float(*number),
ThreadValue::Text(text) => crate::runtime::Value::Text(text.clone()),
ThreadValue::Array(items) => crate::classes::array::of_items(
items.iter().map(|item| item.to_value()).collect(),
),
}
}
pub fn of_value(value: &crate::runtime::Value) -> ThreadValue {
match value {
crate::runtime::Value::Int(number) => ThreadValue::Int(*number),
crate::runtime::Value::Float(number) => ThreadValue::Float(*number),
crate::runtime::Value::Text(text) => ThreadValue::Text(text.clone()),
crate::runtime::Value::List(items) => {
ThreadValue::Array(items.iter().map(ThreadValue::of_value).collect())
}
crate::runtime::Value::Object(object)
if object.borrow().class.eq_ignore_ascii_case("array") =>
{
ThreadValue::Array(
crate::classes::array::the_items(value)
.iter()
.map(ThreadValue::of_value)
.collect(),
)
}
other => match other.to_number() {
Some(number) if crate::runtime::fract(number) == 0.0 => ThreadValue::Int(number as i64),
Some(number) => ThreadValue::Float(number),
None => ThreadValue::Text(other.to_text()),
},
}
}
}
#[cfg(feature = "std")]
pub type SharedGlobals =
std::sync::Arc<std::sync::Mutex<std::collections::BTreeMap<String, crate::runtime::Value>>>;
#[cfg(not(feature = "std"))]
pub type SharedGlobals = ();
#[derive(Clone, Debug, Default)]
pub struct WorkerState {
pub alive: bool,
pub terminated: bool,
pub result: Option<ThreadValue>,
pub exit_code: i64,
pub task: String,
pub error: Option<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())
}
fn create_worker_thread(
&mut self,
_source: &str,
_dialect: &str,
_function: &str,
_args: Vec<ThreadValue>,
_globals: Vec<(String, ThreadValue)>,
_shared: Option<SharedGlobals>,
) -> Result<u64, String> {
Err("this desktop cannot create a worker thread".to_string())
}
fn worker_thread_state(&mut self, _id: u64) -> Result<WorkerState, String> {
Err("this desktop cannot say the state of a worker thread".to_string())
}
fn worker_thread_list(&mut self) -> Result<Vec<(u64, String)>, String> {
Err("this desktop cannot list the worker threads".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())
}
fn msg_box(&mut self, _text: &str, _title: &str, _options: i64) -> Result<String, String> {
Ok("OK".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
+ Com
+ 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,
pub exe: String,
pub pid: i64,
pub text: String,
}
impl WindowInfo {
pub fn has_the_text(&self, wanted: &str) -> bool {
if wanted.is_empty() {
return true;
}
self.text.split('\n').any(|element| element.contains(wanted))
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct TheWindowWanted {
pub asked: bool,
pub title: String,
pub text: String,
pub exclude_titles: Vec<String>,
pub exclude_texts: Vec<String>,
}
fn the_title_of(value: Option<&Value>) -> String {
match value {
Some(Value::Int(_)) => String::new(),
Some(value) => value.to_text(),
None => String::new(),
}
}
impl TheWindowWanted {
pub fn of(values: &[Value], title_at: usize) -> TheWindowWanted {
let wanted = TheWindowWanted {
asked: matches!(
values.get(title_at),
Some(value) if !matches!(value, Value::Int(_))
),
title: the_title_of(values.get(title_at)),
text: values
.get(title_at + 1)
.map(|value| value.to_text())
.unwrap_or_default(),
exclude_titles: values
.get(title_at + 2)
.map(|value| vec![value.to_text()])
.unwrap_or_default(),
exclude_texts: values
.get(title_at + 3)
.map(|value| vec![value.to_text()])
.unwrap_or_default(),
};
wanted.without_the_empty()
}
pub fn without_the_empty(mut self) -> TheWindowWanted {
self.exclude_titles.retain(|title| !title.is_empty());
self.exclude_texts.retain(|text| !text.is_empty());
self
}
}
#[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
}
}