use crate::{
webview::{FileDropHandler, WebviewAttributes, WebviewRpcHandler},
Dispatch, Params, Runtime, WindowBuilder,
};
use serde::Serialize;
use tauri_utils::config::WindowConfig;
use std::hash::{Hash, Hasher};
pub mod dpi;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum WindowEvent {
Resized(dpi::PhysicalSize<u32>),
Moved(dpi::PhysicalPosition<i32>),
CloseRequested,
Destroyed,
Focused(bool),
ScaleFactorChanged {
scale_factor: f64,
new_inner_size: dpi::PhysicalSize<u32>,
},
}
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MenuEvent {
pub menu_item_id: u32,
}
pub struct PendingWindow<P: Params> {
pub label: P::Label,
pub window_builder: <<P::Runtime as Runtime>::Dispatcher as Dispatch>::WindowBuilder,
pub webview_attributes: WebviewAttributes,
pub rpc_handler: Option<WebviewRpcHandler<P>>,
pub file_drop_handler: Option<FileDropHandler<P>>,
pub url: String,
}
impl<P: Params> PendingWindow<P> {
pub fn new(
window_builder: <<P::Runtime as Runtime>::Dispatcher as Dispatch>::WindowBuilder,
webview_attributes: WebviewAttributes,
label: P::Label,
) -> Self {
Self {
window_builder,
webview_attributes,
label,
rpc_handler: None,
file_drop_handler: None,
url: "tauri://localhost".to_string(),
}
}
pub fn with_config(
window_config: WindowConfig,
webview_attributes: WebviewAttributes,
label: P::Label,
) -> Self {
Self {
window_builder:
<<<P::Runtime as Runtime>::Dispatcher as Dispatch>::WindowBuilder>::with_config(
window_config,
),
webview_attributes,
label,
rpc_handler: None,
file_drop_handler: None,
url: "tauri://localhost".to_string(),
}
}
}
pub struct DetachedWindow<P: Params> {
pub label: P::Label,
pub dispatcher: <P::Runtime as Runtime>::Dispatcher,
}
impl<P: Params> Clone for DetachedWindow<P> {
fn clone(&self) -> Self {
Self {
label: self.label.clone(),
dispatcher: self.dispatcher.clone(),
}
}
}
impl<P: Params> Hash for DetachedWindow<P> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.label.hash(state)
}
}
impl<P: Params> Eq for DetachedWindow<P> {}
impl<P: Params> PartialEq for DetachedWindow<P> {
fn eq(&self, other: &Self) -> bool {
self.label.eq(&other.label)
}
}