#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum DownloadProgressParamsState {
InProgress,
Completed,
Canceled,
Unknown(String),
}
impl DownloadProgressParamsState {
pub fn as_str(&self) -> &str {
match self {
Self::InProgress => "inProgress",
Self::Completed => "completed",
Self::Canceled => "canceled",
Self::Unknown(value) => value,
}
}
}
impl AsRef<str> for DownloadProgressParamsState {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl From<String> for DownloadProgressParamsState {
fn from(value: String) -> Self {
match value.as_str() {
"inProgress" => DownloadProgressParamsState::InProgress,
"completed" => DownloadProgressParamsState::Completed,
"canceled" => DownloadProgressParamsState::Canceled,
_ => Self::Unknown(value),
}
}
}
impl serde::Serialize for DownloadProgressParamsState {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(self.as_str())
}
}
impl<'de> serde::Deserialize<'de> for DownloadProgressParamsState {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
struct Visitor;
impl<'de> serde::de::Visitor<'de> for Visitor {
type Value = DownloadProgressParamsState;
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("协议字符串枚举")
}
fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Self::Value, E> {
Ok(match v {
"inProgress" => DownloadProgressParamsState::InProgress,
"completed" => DownloadProgressParamsState::Completed,
"canceled" => DownloadProgressParamsState::Canceled,
_ => DownloadProgressParamsState::Unknown(v.to_owned()),
})
}
fn visit_string<E: serde::de::Error>(self, v: String) -> Result<Self::Value, E> {
Ok(DownloadProgressParamsState::from(v))
}
}
d.deserialize_str(Visitor)
}
}
#[derive(Debug, Clone, serde::Serialize)]
pub struct DownloadProgressParams {
#[serde(rename = "guid")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub guid: String,
#[serde(rename = "totalBytes")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub total_bytes: ydp_core::FiniteF64,
#[serde(rename = "receivedBytes")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub received_bytes: ydp_core::FiniteF64,
#[serde(rename = "state")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub state: DownloadProgressParamsState,
#[serde(rename = "filePath")]
#[serde(
default,
deserialize_with = "ydp_core::binding_support::presence",
skip_serializing_if = "Option::is_none"
)]
pub file_path: Option<String>,
}
impl<'de> serde::Deserialize<'de> for DownloadProgressParams {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
struct Visitor;
impl<'de> serde::de::Visitor<'de> for Visitor {
type Value = DownloadProgressParams;
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("协议 object")
}
fn visit_map<A: serde::de::MapAccess<'de>>(
self,
a: A,
) -> Result<Self::Value, A::Error> {
#[derive(serde::Deserialize)]
struct Fields {
#[serde(rename = "guid")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub guid: String,
#[serde(rename = "totalBytes")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub total_bytes: ydp_core::FiniteF64,
#[serde(rename = "receivedBytes")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub received_bytes: ydp_core::FiniteF64,
#[serde(rename = "state")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub state: DownloadProgressParamsState,
#[serde(rename = "filePath")]
#[serde(
default,
deserialize_with = "ydp_core::binding_support::presence",
skip_serializing_if = "Option::is_none"
)]
pub file_path: Option<String>,
}
let fields = <Fields as serde::Deserialize>::deserialize(
serde::de::value::MapAccessDeserializer::new(a),
)?;
Ok(DownloadProgressParams {
guid: fields.guid,
total_bytes: fields.total_bytes,
received_bytes: fields.received_bytes,
state: fields.state,
file_path: fields.file_path,
})
}
}
d.deserialize_map(Visitor)
}
}
#[derive(Debug, Clone, Copy)]
pub struct DownloadProgress;
impl ydp_core::Event for DownloadProgress {
type Params = DownloadProgressParams;
const METHOD: &'static str = "Browser.downloadProgress";
}
#[derive(Debug, Clone, serde::Serialize)]
pub struct DownloadWillBeginParams {
#[serde(rename = "frameId")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub frame_id: crate::page::types::FrameId,
#[serde(rename = "guid")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub guid: String,
#[serde(rename = "url")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub url: String,
#[serde(rename = "suggestedFilename")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub suggested_filename: String,
}
impl<'de> serde::Deserialize<'de> for DownloadWillBeginParams {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
struct Visitor;
impl<'de> serde::de::Visitor<'de> for Visitor {
type Value = DownloadWillBeginParams;
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("协议 object")
}
fn visit_map<A: serde::de::MapAccess<'de>>(
self,
a: A,
) -> Result<Self::Value, A::Error> {
#[derive(serde::Deserialize)]
struct Fields {
#[serde(rename = "frameId")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub frame_id: crate::page::types::FrameId,
#[serde(rename = "guid")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub guid: String,
#[serde(rename = "url")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub url: String,
#[serde(rename = "suggestedFilename")]
#[serde(deserialize_with = "ydp_core::binding_support::required")]
pub suggested_filename: String,
}
let fields = <Fields as serde::Deserialize>::deserialize(
serde::de::value::MapAccessDeserializer::new(a),
)?;
Ok(DownloadWillBeginParams {
frame_id: fields.frame_id,
guid: fields.guid,
url: fields.url,
suggested_filename: fields.suggested_filename,
})
}
}
d.deserialize_map(Visitor)
}
}
#[derive(Debug, Clone, Copy)]
pub struct DownloadWillBegin;
impl ydp_core::Event for DownloadWillBegin {
type Params = DownloadWillBeginParams;
const METHOD: &'static str = "Browser.downloadWillBegin";
}