browser_commander/playwright/protocol/
dialog.rs1#![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#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct DialogInitializer {
16 #[serde(rename = "page", default, skip_serializing_if = "Option::is_none")]
17 pub page: Option<Ref<Page>>,
18 #[serde(rename = "type")]
19 pub r#type: String,
20 #[serde(rename = "message")]
21 pub message: String,
22 #[serde(rename = "defaultValue")]
23 pub default_value: String,
24}
25
26#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
28pub struct DialogAcceptParams {
29 #[serde(rename = "promptText", default, skip_serializing_if = "Option::is_none")]
30 pub prompt_text: Option<String>,
31}
32
33#[derive(Debug, Clone, PartialEq)]
35pub enum DialogEvent {
36 Unknown {
38 method: String,
40 params: serde_json::Value,
42 },
43}
44
45impl ProtocolEvent for DialogEvent {
46 fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
47 match method {
48 _ => Ok(Self::Unknown { method: method.to_string(), params }),
49 }
50 }
51}
52
53#[derive(Debug, Clone)]
55pub struct Dialog {
56 channel: Channel,
57}
58
59impl ChannelType for Dialog {
60 const INTERFACE: &'static str = "Dialog";
61 type Initializer = DialogInitializer;
62 type Event = DialogEvent;
63
64 fn accepts(interface: &str) -> bool {
65 matches!(interface, "Dialog")
66 }
67
68 fn from_channel(channel: Channel) -> Self {
69 Self { channel }
70 }
71
72 fn channel(&self) -> &Channel {
73 &self.channel
74 }
75}
76
77impl Dialog {
78 pub async fn accept(&self, params: DialogAcceptParams) -> Result<(), ProtocolError> {
80 self.channel.send_no_result("accept", ¶ms).await
81 }
82
83 pub async fn dismiss(&self) -> Result<(), ProtocolError> {
85 self.channel.send_no_result("dismiss", &serde_json::json!({})).await
86 }
87}