use serde::{Deserialize, Serialize};
use tao::window::WindowId;
#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum UserWindowEvent {
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
GlobalHotKeyEvent(global_hotkey::GlobalHotKeyEvent),
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
MudaMenuEvent(muda::MenuEvent),
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
TrayIconEvent(tray_icon::TrayIconEvent),
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
TrayMenuEvent(tray_icon::menu::MenuEvent),
Poll(WindowId),
Ipc {
id: WindowId,
msg: IpcMessage,
},
#[cfg(all(feature = "devtools", debug_assertions))]
HotReloadEvent(dioxus_devtools::DevserverMsg),
WindowsDragDrop(WindowId),
WindowsDragOver(WindowId, i32, i32),
WindowsDragLeave(WindowId),
NewWindow,
CloseWindow(WindowId),
Shutdown,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct IpcMessage {
method: String,
params: serde_json::Value,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum IpcMethod<'a> {
UserEvent,
Query,
BrowserOpen,
Initialize,
Other(&'a str),
}
impl IpcMessage {
pub(crate) fn method(&self) -> IpcMethod<'_> {
match self.method.as_str() {
"user_event" => IpcMethod::UserEvent,
"query" => IpcMethod::Query,
"browser_open" => IpcMethod::BrowserOpen,
"initialize" => IpcMethod::Initialize,
_ => IpcMethod::Other(&self.method),
}
}
pub(crate) fn params(self) -> serde_json::Value {
self.params
}
}