dioxus/packages/desktop/src/events.rs

38 lines
968 B
Rust
Raw Normal View History

2022-02-13 18:56:11 +00:00
//! Convert a serialized event to an event trigger
use serde::{Deserialize, Serialize};
2022-12-31 17:19:21 +00:00
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct IpcMessage {
2022-02-13 18:56:11 +00:00
method: String,
params: serde_json::Value,
}
2024-01-04 23:21:30 +00:00
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum KnownIpcMethod<'a> {
FileDialog,
UserEvent,
Query,
BrowserOpen,
Initialize,
Other(&'a str),
}
2022-02-13 18:56:11 +00:00
impl IpcMessage {
2024-01-04 23:21:30 +00:00
pub(crate) fn method(&self) -> KnownIpcMethod {
match self.method.as_str() {
// todo: this is a misspelling
"file_diolog" => KnownIpcMethod::FileDialog,
"user_event" => KnownIpcMethod::UserEvent,
"query" => KnownIpcMethod::Query,
"browser_open" => KnownIpcMethod::BrowserOpen,
"initialize" => KnownIpcMethod::Initialize,
_ => KnownIpcMethod::Other(&self.method),
}
2022-02-13 18:56:11 +00:00
}
pub(crate) fn params(self) -> serde_json::Value {
self.params
}
}