audb_core/features/input/
tap.rs

1// Tap command implementation for Aurora OS devices
2//
3// This feature requires root access to work properly. The Python script uses
4// /dev/uinput which needs root permissions via devel-su.
5
6use crate::features::config::{device_store::DeviceStore, state::DeviceState};
7use crate::features::input::scripts::ScriptManager;
8use crate::tools::{
9    macros::print_info,
10    session::DeviceSession,
11    types::DeviceIdentifier,
12};
13use anyhow::{anyhow, Context, Result};
14
15pub async fn execute(x: u16, y: u16) -> Result<()> {
16    // Validate coordinates
17    if x > 4096 || y > 4096 {
18        return Err(anyhow!("Coordinates out of range: ({}, {}). Max: 4096x4096", x, y));
19    }
20
21    // Get device and establish session
22    let current_host = DeviceState::get_current()?;
23    let device_id = DeviceIdentifier::Host(current_host);
24    let device = DeviceStore::find(&device_id)?;
25
26    print_info(format!("Tapping at ({}, {}) on device {}", x, y, device.display_name()));
27    print_info(format!("Connecting to {}:{}...", device.host, device.port));
28
29    let mut session = DeviceSession::connect(&device)
30        .context("Failed to connect to device")?;
31
32    // Ensure tap script is present on device
33    ScriptManager::ensure_tap_script_with_session(&mut session)?;
34
35    // Execute tap command using devel-su for root access
36    let script_path = ScriptManager::tap_script_path();
37    let tap_command = format!("python3 {} {} {}", script_path, x, y);
38
39    print_info("Executing tap with devel-su...");
40
41    let output = session.exec_as_root(&tap_command)
42        .context("Tap requires root access. Set root password using: audb device add")?;
43
44    // Display output
45    for line in &output {
46        if !line.is_empty() {
47            println!("{}", line);
48        }
49    }
50
51    print_info("Tap completed successfully");
52    Ok(())
53}