use crate::{menu::Menu, window::DetachedWindow, Icon};
use tauri_utils::{
config::{WindowConfig, WindowUrl},
Theme,
};
#[cfg(windows)]
use windows::Win32::Foundation::HWND;
use std::{fmt, path::PathBuf};
#[derive(Debug, Clone)]
pub struct WebviewAttributes {
pub url: WindowUrl,
pub initialization_scripts: Vec<String>,
pub data_directory: Option<PathBuf>,
pub file_drop_handler_enabled: bool,
pub clipboard: bool,
}
impl WebviewAttributes {
pub fn new(url: WindowUrl) -> Self {
Self {
url,
initialization_scripts: Vec::new(),
data_directory: None,
file_drop_handler_enabled: true,
clipboard: false,
}
}
#[must_use]
pub fn initialization_script(mut self, script: &str) -> Self {
self.initialization_scripts.push(script.to_string());
self
}
#[must_use]
pub fn data_directory(mut self, data_directory: PathBuf) -> Self {
self.data_directory.replace(data_directory);
self
}
#[must_use]
pub fn disable_file_drop_handler(mut self) -> Self {
self.file_drop_handler_enabled = false;
self
}
#[must_use]
pub fn enable_clipboard_access(mut self) -> Self {
self.clipboard = true;
self
}
}
pub trait WindowBuilderBase: fmt::Debug + Clone + Sized {}
pub trait WindowBuilder: WindowBuilderBase {
fn new() -> Self;
fn with_config(config: WindowConfig) -> Self;
#[must_use]
fn menu(self, menu: Menu) -> Self;
#[must_use]
fn center(self) -> Self;
#[must_use]
fn position(self, x: f64, y: f64) -> Self;
#[must_use]
fn inner_size(self, width: f64, height: f64) -> Self;
#[must_use]
fn min_inner_size(self, min_width: f64, min_height: f64) -> Self;
#[must_use]
fn max_inner_size(self, max_width: f64, max_height: f64) -> Self;
#[must_use]
fn resizable(self, resizable: bool) -> Self;
#[must_use]
fn title<S: Into<String>>(self, title: S) -> Self;
#[must_use]
fn fullscreen(self, fullscreen: bool) -> Self;
#[must_use]
fn focus(self) -> Self;
#[must_use]
fn maximized(self, maximized: bool) -> Self;
#[must_use]
fn visible(self, visible: bool) -> Self;
#[cfg(any(not(target_os = "macos"), feature = "macos-private-api"))]
#[cfg_attr(
doc_cfg,
doc(cfg(any(not(target_os = "macos"), feature = "macos-private-api")))
)]
#[must_use]
fn transparent(self, transparent: bool) -> Self;
#[must_use]
fn decorations(self, decorations: bool) -> Self;
#[must_use]
fn always_on_top(self, always_on_top: bool) -> Self;
fn icon(self, icon: Icon) -> crate::Result<Self>;
#[must_use]
fn skip_taskbar(self, skip: bool) -> Self;
#[cfg(windows)]
#[must_use]
fn parent_window(self, parent: HWND) -> Self;
#[cfg(target_os = "macos")]
#[must_use]
fn parent_window(self, parent: *mut std::ffi::c_void) -> Self;
#[cfg(windows)]
#[must_use]
fn owner_window(self, owner: HWND) -> Self;
fn theme(self, theme: Option<Theme>) -> Self;
fn has_icon(&self) -> bool;
fn get_menu(&self) -> Option<&Menu>;
}
pub type WebviewIpcHandler<T, R> = Box<dyn Fn(DetachedWindow<T, R>, String) + Send>;