2022-02-13 18:56:11 +00:00
|
|
|
//! Convert a serialized event to an event trigger
|
2021-07-24 06:52:05 +00:00
|
|
|
|
2022-07-06 16:05:31 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-07-24 06:52:05 +00:00
|
|
|
|
2022-12-31 17:19:21 +00:00
|
|
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
2022-12-30 06:52:54 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|