(
session: SimulatorSession,
message: ControlMessage,
)
| 2998 | } |
| 2999 | |
| 3000 | pub(crate) async fn run_control_message( |
| 3001 | session: SimulatorSession, |
| 3002 | message: ControlMessage, |
| 3003 | ) -> Result<(), AppError> { |
| 3004 | task::spawn_blocking(move || match message { |
| 3005 | ControlMessage::Touch { x, y, phase } => { |
| 3006 | if !x.is_finite() || !y.is_finite() { |
| 3007 | return Err(AppError::bad_request( |
| 3008 | "`x` and `y` must be finite normalized numbers.", |
| 3009 | )); |
| 3010 | } |
| 3011 | session.send_touch(x.clamp(0.0, 1.0), y.clamp(0.0, 1.0), &phase) |
| 3012 | } |
| 3013 | ControlMessage::EdgeTouch { x, y, phase, edge } => { |
| 3014 | if !x.is_finite() || !y.is_finite() { |
| 3015 | return Err(AppError::bad_request( |
| 3016 | "`x` and `y` must be finite normalized numbers.", |
| 3017 | )); |
| 3018 | } |
| 3019 | let edge = edge_name_to_hid_value(edge.as_str()).ok_or_else(|| { |
| 3020 | AppError::bad_request("`edge` must be `left`, `top`, `bottom`, `right`, or `none`.") |
| 3021 | })?; |
| 3022 | session.send_edge_touch(x.clamp(0.0, 1.0), y.clamp(0.0, 1.0), &phase, edge) |
| 3023 | } |
| 3024 | ControlMessage::MultiTouch { |
| 3025 | x1, |
| 3026 | y1, |
| 3027 | x2, |
| 3028 | y2, |
| 3029 | phase, |
| 3030 | } => { |
| 3031 | if !x1.is_finite() || !y1.is_finite() || !x2.is_finite() || !y2.is_finite() { |
| 3032 | return Err(AppError::bad_request( |
| 3033 | "`x1`, `y1`, `x2`, and `y2` must be finite normalized numbers.", |
| 3034 | )); |
| 3035 | } |
| 3036 | session.send_multitouch( |
| 3037 | x1.clamp(0.0, 1.0), |
| 3038 | y1.clamp(0.0, 1.0), |
| 3039 | x2.clamp(0.0, 1.0), |
| 3040 | y2.clamp(0.0, 1.0), |
| 3041 | &phase, |
| 3042 | ) |
| 3043 | } |
| 3044 | ControlMessage::Key { |
| 3045 | key_code, |
| 3046 | modifiers, |
| 3047 | } => session.send_key(key_code, modifiers.unwrap_or(0)), |
| 3048 | ControlMessage::Button { |
| 3049 | button, |
| 3050 | duration_ms, |
| 3051 | phase, |
| 3052 | usage_page, |
| 3053 | usage, |
| 3054 | } => { |
| 3055 | if let Some(phase) = phase { |
| 3056 | let pressed = match phase.as_str() { |
| 3057 | "down" | "began" => true, |
no test coverage detected