mod commands;
mod controller;
mod selector;
mod target;
use std::rc::Rc;
use waft_embedder::{ServiceExtensionError, ServiceExtensionParams, ServiceExtensionResult};
use waft_foundation::{App, ServiceExtensions, Task};
const COMMANDS: &str = "get_health, find, tap, long_press, enter_text, send_text_input_action, \
scroll, scroll_into_view, get_offset, wait_for, get_text, screenshot";
pub(crate) fn init_service_extensions(app: &mut App) {
ServiceExtensions::register(app, "ext.waft.driver", Rc::new(driver_command));
}
fn driver_command(app: &mut App, params: ServiceExtensionParams) -> Task<ServiceExtensionResult> {
let command = match params.require("command") {
Ok(command) => command.to_owned(),
Err(error) => return Task::ready(Err(error)),
};
match command.as_str() {
"get_health" => Task::ready(commands::get_health()),
"find" => Task::ready(commands::find(app, ¶ms)),
"screenshot" => commands::screenshot(app, ¶ms),
"tap" => app.spawn(async move |cx| commands::tap(cx, ¶ms).await),
"long_press" => app.spawn(async move |cx| commands::long_press(cx, ¶ms).await),
"enter_text" => app.spawn(async move |cx| commands::enter_text(cx, ¶ms).await),
"send_text_input_action" => {
app.spawn(async move |cx| commands::send_text_input_action(cx, ¶ms).await)
}
"scroll" => app.spawn(async move |cx| commands::scroll(cx, ¶ms).await),
"scroll_into_view" => {
app.spawn(async move |cx| commands::scroll_into_view(cx, ¶ms).await)
}
"get_offset" => app.spawn(async move |cx| commands::get_offset(cx, ¶ms).await),
"wait_for" => app.spawn(async move |cx| commands::wait_for(cx, ¶ms).await),
"get_text" => app.spawn(async move |cx| commands::get_text(cx, ¶ms).await),
other => Task::ready(Err(ServiceExtensionError::InvalidParams(format!(
"`{other}` is no driver command; the commands are {COMMANDS}"
)))),
}
}
#[cfg(test)]
mod tests;