2022-07-06 16:05:31 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2024-01-05 04:27:04 +00:00
|
|
|
use tao::window::WindowId;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct UserWindowEvent(pub EventData, pub WindowId);
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub enum EventData {
|
|
|
|
Poll,
|
|
|
|
|
|
|
|
Ipc(IpcMessage),
|
|
|
|
|
|
|
|
#[cfg(all(feature = "hot-reload", debug_assertions))]
|
|
|
|
HotReloadEvent(dioxus_hot_reload::HotReloadMsg),
|
|
|
|
|
|
|
|
NewWindow,
|
|
|
|
|
|
|
|
CloseWindow,
|
|
|
|
}
|
2021-07-24 06:52:05 +00:00
|
|
|
|
2024-01-05 04:17:38 +00:00
|
|
|
/// A message struct that manages the communication between the webview and the eventloop code
|
|
|
|
///
|
|
|
|
/// This needs to be serializable across the JS boundary, so the method names and structs are sensitive.
|
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-05 04:17:38 +00:00
|
|
|
/// A set of known messages that we need to respond to
|
2024-01-04 23:21:30 +00:00
|
|
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
2024-01-05 00:48:53 +00:00
|
|
|
pub enum IpcMethod<'a> {
|
2024-01-04 23:21:30 +00:00
|
|
|
FileDialog,
|
|
|
|
UserEvent,
|
|
|
|
Query,
|
|
|
|
BrowserOpen,
|
|
|
|
Initialize,
|
|
|
|
Other(&'a str),
|
|
|
|
}
|
|
|
|
|
2022-02-13 18:56:11 +00:00
|
|
|
impl IpcMessage {
|
2024-01-05 00:48:53 +00:00
|
|
|
pub(crate) fn method(&self) -> IpcMethod {
|
2024-01-04 23:21:30 +00:00
|
|
|
match self.method.as_str() {
|
2024-01-05 04:17:38 +00:00
|
|
|
// todo: this is a misspelling, needs to be fixed
|
2024-01-05 00:48:53 +00: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 23:21:30 +00:00
|
|
|
}
|
2022-02-13 18:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn params(self) -> serde_json::Value {
|
|
|
|
self.params
|
|
|
|
}
|
|
|
|
}
|