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