Skip to main content

browser_commander/playwright/protocol/
android.rs

1// @generated by scripts/generate-playwright-protocol.mjs from
2// rust/protocol/playwright/*.yml. Do not edit by hand.
3
4#![allow(clippy::all, missing_docs, unused_imports)]
5
6use serde::{Deserialize, Serialize};
7
8use super::*;
9use crate::playwright::connection::{
10    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
11};
12
13/// Initializer the driver sends when it creates a `Android`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct AndroidInitializer {}
16
17/// Parameters of `Android.devices`.
18#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
19pub struct AndroidDevicesParams {
20    #[serde(rename = "host", default, skip_serializing_if = "Option::is_none")]
21    pub host: Option<String>,
22    #[serde(rename = "port", default, skip_serializing_if = "Option::is_none")]
23    pub port: Option<i64>,
24    #[serde(rename = "omitDriverInstall", default, skip_serializing_if = "Option::is_none")]
25    pub omit_driver_install: Option<bool>,
26}
27
28/// Result of `Android.devices`.
29#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
30pub struct AndroidDevicesResult {
31    #[serde(rename = "devices")]
32    pub devices: Vec<Ref<AndroidDevice>>,
33}
34
35/// Events a `Android` channel can emit.
36#[derive(Debug, Clone, PartialEq)]
37pub enum AndroidEvent {
38    /// An event this binding does not know (a newer driver).
39    Unknown {
40        /// Event name.
41        method: String,
42        /// Raw event parameters.
43        params: serde_json::Value,
44    },
45}
46
47impl ProtocolEvent for AndroidEvent {
48    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
49        match method {
50            _ => Ok(Self::Unknown { method: method.to_string(), params }),
51        }
52    }
53}
54
55/// Channel for the `Android` interface (`android.yml`).
56#[derive(Debug, Clone)]
57pub struct Android {
58    channel: Channel,
59}
60
61impl ChannelType for Android {
62    const INTERFACE: &'static str = "Android";
63    type Initializer = AndroidInitializer;
64    type Event = AndroidEvent;
65
66    fn accepts(interface: &str) -> bool {
67        matches!(interface, "Android")
68    }
69
70    fn from_channel(channel: Channel) -> Self {
71        Self { channel }
72    }
73
74    fn channel(&self) -> &Channel {
75        &self.channel
76    }
77}
78
79impl Android {
80    /// `Android.devices` (internal).
81    pub async fn devices(&self, params: AndroidDevicesParams) -> Result<AndroidDevicesResult, ProtocolError> {
82        self.channel.send("devices", &params).await
83    }
84}