#![cfg_attr(doc_cfg, feature(doc_cfg))]
use std::{fmt::Debug, hash::Hash, path::PathBuf};
use serde::Serialize;
use tauri_utils::assets::Assets;
use uuid::Uuid;
#[cfg(any(feature = "menu", feature = "system-tray"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "menu", feature = "system-tray"))))]
pub mod menu;
pub mod monitor;
pub mod tag;
pub mod webview;
pub mod window;
use monitor::Monitor;
use tag::Tag;
use webview::WindowBuilder;
use window::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
DetachedWindow, PendingWindow, WindowEvent,
};
pub trait MenuId: Serialize + Hash + Eq + Debug + Clone + Send + Sync + 'static {}
impl<T> MenuId for T where T: Serialize + Hash + Eq + Debug + Clone + Send + Sync + 'static {}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("failed to create webview: {0}")]
CreateWebview(Box<dyn std::error::Error + Send>),
#[error("failed to create window")]
CreateWindow,
#[error("failed to send message to the webview")]
FailedToSendMessage,
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[cfg(feature = "system-tray")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
#[error("error encountered during tray setup: {0}")]
SystemTray(Box<dyn std::error::Error + Send>),
#[error("invalid icon: {0}")]
InvalidIcon(Box<dyn std::error::Error + Send>),
}
pub type Result<T> = std::result::Result<T, Error>;
#[doc(hidden)]
pub mod private {
pub trait ParamsBase {}
}
pub trait Params: private::ParamsBase + 'static {
type Event: Tag;
type Label: Tag;
type MenuId: MenuId;
type SystemTrayMenuId: MenuId;
type Assets: Assets;
type Runtime: Runtime;
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum Icon {
File(PathBuf),
Raw(Vec<u8>),
}
pub struct SystemTrayEvent {
pub menu_item_id: u32,
}
pub trait Runtime: Sized + 'static {
type Dispatcher: Dispatch<Runtime = Self>;
fn new() -> crate::Result<Self>;
fn create_window<P: Params<Runtime = Self>>(
&self,
pending: PendingWindow<P>,
) -> crate::Result<DetachedWindow<P>>;
#[cfg(feature = "system-tray")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
fn system_tray<I: MenuId>(
&self,
icon: Icon,
menu: Vec<menu::SystemTrayMenuItem<I>>,
) -> crate::Result<()>;
#[cfg(feature = "system-tray")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
fn on_system_tray_event<F: Fn(&SystemTrayEvent) + Send + 'static>(&mut self, f: F) -> Uuid;
fn run(self);
}
pub trait Dispatch: Clone + Send + Sized + 'static {
type Runtime: Runtime;
type WindowBuilder: WindowBuilder + Clone;
fn run_on_main_thread<F: FnOnce() + Send + 'static>(&self, f: F) -> crate::Result<()>;
fn on_window_event<F: Fn(&WindowEvent) + Send + 'static>(&self, f: F) -> Uuid;
#[cfg(feature = "menu")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "menu")))]
fn on_menu_event<F: Fn(&window::MenuEvent) + Send + 'static>(&self, f: F) -> Uuid;
fn scale_factor(&self) -> crate::Result<f64>;
fn inner_position(&self) -> crate::Result<PhysicalPosition<i32>>;
fn outer_position(&self) -> crate::Result<PhysicalPosition<i32>>;
fn inner_size(&self) -> crate::Result<PhysicalSize<u32>>;
fn outer_size(&self) -> crate::Result<PhysicalSize<u32>>;
fn is_fullscreen(&self) -> crate::Result<bool>;
fn is_maximized(&self) -> crate::Result<bool>;
fn current_monitor(&self) -> crate::Result<Option<Monitor>>;
fn primary_monitor(&self) -> crate::Result<Option<Monitor>>;
fn available_monitors(&self) -> crate::Result<Vec<Monitor>>;
fn print(&self) -> crate::Result<()>;
fn create_window<P: Params<Runtime = Self::Runtime>>(
&mut self,
pending: PendingWindow<P>,
) -> crate::Result<DetachedWindow<P>>;
fn set_resizable(&self, resizable: bool) -> crate::Result<()>;
fn set_title<S: Into<String>>(&self, title: S) -> crate::Result<()>;
fn maximize(&self) -> crate::Result<()>;
fn unmaximize(&self) -> crate::Result<()>;
fn minimize(&self) -> crate::Result<()>;
fn unminimize(&self) -> crate::Result<()>;
fn show(&self) -> crate::Result<()>;
fn hide(&self) -> crate::Result<()>;
fn close(&self) -> crate::Result<()>;
fn set_decorations(&self, decorations: bool) -> crate::Result<()>;
fn set_always_on_top(&self, always_on_top: bool) -> crate::Result<()>;
fn set_size(&self, size: Size) -> crate::Result<()>;
fn set_min_size(&self, size: Option<Size>) -> crate::Result<()>;
fn set_max_size(&self, size: Option<Size>) -> crate::Result<()>;
fn set_position(&self, position: Position) -> crate::Result<()>;
fn set_fullscreen(&self, fullscreen: bool) -> crate::Result<()>;
fn set_icon(&self, icon: Icon) -> crate::Result<()>;
fn start_dragging(&self) -> crate::Result<()>;
fn eval_script<S: Into<String>>(&self, script: S) -> crate::Result<()>;
}