tauri_runtime/
lib.rs

1// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
2// SPDX-License-Identifier: Apache-2.0
3// SPDX-License-Identifier: MIT
4
5//! Internal runtime between Tauri and the underlying webview runtime.
6//!
7//! None of the exposed API of this crate is stable, and it may break semver
8//! compatibility in the future. The major version only signifies the intended Tauri version.
9
10#![doc(
11  html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/.github/icon.png",
12  html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/.github/icon.png"
13)]
14#![cfg_attr(docsrs, feature(doc_cfg))]
15
16use raw_window_handle::DisplayHandle;
17use serde::{Deserialize, Serialize};
18use std::{borrow::Cow, fmt::Debug, sync::mpsc::Sender};
19use tauri_utils::config::Color;
20use tauri_utils::Theme;
21use url::Url;
22use webview::{DetachedWebview, PendingWebview};
23
24/// Types useful for interacting with a user's monitors.
25pub mod monitor;
26pub mod webview;
27pub mod window;
28
29use dpi::{PhysicalPosition, PhysicalSize, Position, Size};
30use monitor::Monitor;
31use window::{
32  CursorIcon, DetachedWindow, PendingWindow, RawWindow, WebviewEvent, WindowEvent,
33  WindowSizeConstraints,
34};
35use window::{WindowBuilder, WindowId};
36
37use http::{
38  header::{InvalidHeaderName, InvalidHeaderValue},
39  method::InvalidMethod,
40  status::InvalidStatusCode,
41};
42
43/// UI scaling utilities.
44pub use dpi;
45
46pub type WindowEventId = u32;
47pub type WebviewEventId = u32;
48
49/// A rectangular region.
50#[derive(Clone, Copy, Debug, Serialize)]
51pub struct Rect {
52  /// Rect position.
53  pub position: dpi::Position,
54  /// Rect size.
55  pub size: dpi::Size,
56}
57
58impl Default for Rect {
59  fn default() -> Self {
60    Self {
61      position: Position::Logical((0, 0).into()),
62      size: Size::Logical((0, 0).into()),
63    }
64  }
65}
66
67/// Progress bar status.
68#[derive(Debug, Clone, Copy, Deserialize)]
69#[serde(rename_all = "camelCase")]
70pub enum ProgressBarStatus {
71  /// Hide progress bar.
72  None,
73  /// Normal state.
74  Normal,
75  /// Indeterminate state. **Treated as Normal on Linux and macOS**
76  Indeterminate,
77  /// Paused state. **Treated as Normal on Linux**
78  Paused,
79  /// Error state. **Treated as Normal on Linux**
80  Error,
81}
82
83/// Progress Bar State
84#[derive(Debug, Deserialize)]
85#[serde(rename_all = "camelCase")]
86pub struct ProgressBarState {
87  /// The progress bar status.
88  pub status: Option<ProgressBarStatus>,
89  /// The progress bar progress. This can be a value ranging from `0` to `100`
90  pub progress: Option<u64>,
91  /// The `.desktop` filename with the Unity desktop window manager, for example `myapp.desktop` **Linux Only**
92  pub desktop_filename: Option<String>,
93}
94
95/// Type of user attention requested on a window.
96#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
97#[serde(tag = "type")]
98pub enum UserAttentionType {
99  /// ## Platform-specific
100  /// - **macOS:** Bounces the dock icon until the application is in focus.
101  /// - **Windows:** Flashes both the window and the taskbar button until the application is in focus.
102  Critical,
103  /// ## Platform-specific
104  /// - **macOS:** Bounces the dock icon once.
105  /// - **Windows:** Flashes the taskbar button until the application is in focus.
106  Informational,
107}
108
109#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
110#[serde(tag = "type")]
111pub enum DeviceEventFilter {
112  /// Always filter out device events.
113  Always,
114  /// Filter out device events while the window is not focused.
115  Unfocused,
116  /// Report all device events regardless of window focus.
117  Never,
118}
119
120impl Default for DeviceEventFilter {
121  fn default() -> Self {
122    Self::Unfocused
123  }
124}
125
126/// Defines the orientation that a window resize will be performed.
127#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
128pub enum ResizeDirection {
129  East,
130  North,
131  NorthEast,
132  NorthWest,
133  South,
134  SouthEast,
135  SouthWest,
136  West,
137}
138
139#[derive(Debug, thiserror::Error)]
140#[non_exhaustive]
141pub enum Error {
142  /// Failed to create webview.
143  #[error("failed to create webview: {0}")]
144  CreateWebview(Box<dyn std::error::Error + Send + Sync>),
145  /// Failed to create window.
146  #[error("failed to create window")]
147  CreateWindow,
148  /// The given window label is invalid.
149  #[error("Window labels must only include alphanumeric characters, `-`, `/`, `:` and `_`.")]
150  InvalidWindowLabel,
151  /// Failed to send message to webview.
152  #[error("failed to send message to the webview")]
153  FailedToSendMessage,
154  /// Failed to receive message from webview.
155  #[error("failed to receive message from webview")]
156  FailedToReceiveMessage,
157  /// Failed to serialize/deserialize.
158  #[error("JSON error: {0}")]
159  Json(#[from] serde_json::Error),
160  /// Failed to load window icon.
161  #[error("invalid icon: {0}")]
162  InvalidIcon(Box<dyn std::error::Error + Send + Sync>),
163  /// Failed to get monitor on window operation.
164  #[error("failed to get monitor")]
165  FailedToGetMonitor,
166  /// Failed to get cursor position.
167  #[error("failed to get cursor position")]
168  FailedToGetCursorPosition,
169  #[error("Invalid header name: {0}")]
170  InvalidHeaderName(#[from] InvalidHeaderName),
171  #[error("Invalid header value: {0}")]
172  InvalidHeaderValue(#[from] InvalidHeaderValue),
173  #[error("Invalid status code: {0}")]
174  InvalidStatusCode(#[from] InvalidStatusCode),
175  #[error("Invalid method: {0}")]
176  InvalidMethod(#[from] InvalidMethod),
177  #[error("Infallible error, something went really wrong: {0}")]
178  Infallible(#[from] std::convert::Infallible),
179  #[error("the event loop has been closed")]
180  EventLoopClosed,
181  #[error("Invalid proxy url")]
182  InvalidProxyUrl,
183  #[error("window not found")]
184  WindowNotFound,
185}
186
187/// Result type.
188pub type Result<T> = std::result::Result<T, Error>;
189
190/// Window icon.
191#[derive(Debug, Clone)]
192pub struct Icon<'a> {
193  /// RGBA bytes of the icon.
194  pub rgba: Cow<'a, [u8]>,
195  /// Icon width.
196  pub width: u32,
197  /// Icon height.
198  pub height: u32,
199}
200
201/// A type that can be used as an user event.
202pub trait UserEvent: Debug + Clone + Send + 'static {}
203
204impl<T: Debug + Clone + Send + 'static> UserEvent for T {}
205
206/// Event triggered on the event loop run.
207#[derive(Debug)]
208#[non_exhaustive]
209pub enum RunEvent<T: UserEvent> {
210  /// Event loop is exiting.
211  Exit,
212  /// Event loop is about to exit
213  ExitRequested {
214    /// The exit code.
215    code: Option<i32>,
216    tx: Sender<ExitRequestedEventAction>,
217  },
218  /// An event associated with a window.
219  WindowEvent {
220    /// The window label.
221    label: String,
222    /// The detailed event.
223    event: WindowEvent,
224  },
225  /// An event associated with a webview.
226  WebviewEvent {
227    /// The webview label.
228    label: String,
229    /// The detailed event.
230    event: WebviewEvent,
231  },
232  /// Application ready.
233  Ready,
234  /// Sent if the event loop is being resumed.
235  Resumed,
236  /// Emitted when all of the event loop's input events have been processed and redraw processing is about to begin.
237  ///
238  /// This event is useful as a place to put your code that should be run after all state-changing events have been handled and you want to do stuff (updating state, performing calculations, etc) that happens as the “main body” of your event loop.
239  MainEventsCleared,
240  /// Emitted when the user wants to open the specified resource with the app.
241  #[cfg(any(target_os = "macos", target_os = "ios"))]
242  Opened { urls: Vec<url::Url> },
243  /// Emitted when the NSApplicationDelegate's applicationShouldHandleReopen gets called
244  #[cfg(target_os = "macos")]
245  Reopen {
246    /// Indicates whether the NSApplication object found any visible windows in your application.
247    has_visible_windows: bool,
248  },
249  /// A custom event defined by the user.
250  UserEvent(T),
251}
252
253/// Action to take when the event loop is about to exit
254#[derive(Debug)]
255pub enum ExitRequestedEventAction {
256  /// Prevent the event loop from exiting
257  Prevent,
258}
259
260/// Application's activation policy. Corresponds to NSApplicationActivationPolicy.
261#[cfg(target_os = "macos")]
262#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
263#[non_exhaustive]
264pub enum ActivationPolicy {
265  /// Corresponds to NSApplicationActivationPolicyRegular.
266  Regular,
267  /// Corresponds to NSApplicationActivationPolicyAccessory.
268  Accessory,
269  /// Corresponds to NSApplicationActivationPolicyProhibited.
270  Prohibited,
271}
272
273/// A [`Send`] handle to the runtime.
274pub trait RuntimeHandle<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static {
275  type Runtime: Runtime<T, Handle = Self>;
276
277  /// Creates an `EventLoopProxy` that can be used to dispatch user events to the main event loop.
278  fn create_proxy(&self) -> <Self::Runtime as Runtime<T>>::EventLoopProxy;
279
280  /// Sets the activation policy for the application.
281  #[cfg(target_os = "macos")]
282  #[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
283  fn set_activation_policy(&self, activation_policy: ActivationPolicy) -> Result<()>;
284
285  /// Requests an exit of the event loop.
286  fn request_exit(&self, code: i32) -> Result<()>;
287
288  /// Create a new window.
289  fn create_window<F: Fn(RawWindow) + Send + 'static>(
290    &self,
291    pending: PendingWindow<T, Self::Runtime>,
292    before_window_creation: Option<F>,
293  ) -> Result<DetachedWindow<T, Self::Runtime>>;
294
295  /// Create a new webview.
296  fn create_webview(
297    &self,
298    window_id: WindowId,
299    pending: PendingWebview<T, Self::Runtime>,
300  ) -> Result<DetachedWebview<T, Self::Runtime>>;
301
302  /// Run a task on the main thread.
303  fn run_on_main_thread<F: FnOnce() + Send + 'static>(&self, f: F) -> Result<()>;
304
305  fn display_handle(&self) -> std::result::Result<DisplayHandle, raw_window_handle::HandleError>;
306
307  fn primary_monitor(&self) -> Option<Monitor>;
308  fn monitor_from_point(&self, x: f64, y: f64) -> Option<Monitor>;
309  fn available_monitors(&self) -> Vec<Monitor>;
310
311  fn cursor_position(&self) -> Result<PhysicalPosition<f64>>;
312
313  fn set_theme(&self, theme: Option<Theme>);
314
315  /// Shows the application, but does not automatically focus it.
316  #[cfg(target_os = "macos")]
317  #[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
318  fn show(&self) -> Result<()>;
319
320  /// Hides the application.
321  #[cfg(target_os = "macos")]
322  #[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
323  fn hide(&self) -> Result<()>;
324
325  /// Finds an Android class in the project scope.
326  #[cfg(target_os = "android")]
327  fn find_class<'a>(
328    &self,
329    env: &mut jni::JNIEnv<'a>,
330    activity: &jni::objects::JObject<'_>,
331    name: impl Into<String>,
332  ) -> std::result::Result<jni::objects::JClass<'a>, jni::errors::Error>;
333
334  /// Dispatch a closure to run on the Android context.
335  ///
336  /// The closure takes the JNI env, the Android activity instance and the possibly null webview.
337  #[cfg(target_os = "android")]
338  fn run_on_android_context<F>(&self, f: F)
339  where
340    F: FnOnce(&mut jni::JNIEnv, &jni::objects::JObject, &jni::objects::JObject) + Send + 'static;
341}
342
343pub trait EventLoopProxy<T: UserEvent>: Debug + Clone + Send + Sync {
344  fn send_event(&self, event: T) -> Result<()>;
345}
346
347#[derive(Default)]
348pub struct RuntimeInitArgs {
349  #[cfg(any(
350    target_os = "linux",
351    target_os = "dragonfly",
352    target_os = "freebsd",
353    target_os = "netbsd",
354    target_os = "openbsd"
355  ))]
356  pub app_id: Option<String>,
357  #[cfg(windows)]
358  pub msg_hook: Option<Box<dyn FnMut(*const std::ffi::c_void) -> bool + 'static>>,
359}
360
361/// The webview runtime interface.
362pub trait Runtime<T: UserEvent>: Debug + Sized + 'static {
363  /// The window message dispatcher.
364  type WindowDispatcher: WindowDispatch<T, Runtime = Self>;
365  /// The webview message dispatcher.
366  type WebviewDispatcher: WebviewDispatch<T, Runtime = Self>;
367  /// The runtime handle type.
368  type Handle: RuntimeHandle<T, Runtime = Self>;
369  /// The proxy type.
370  type EventLoopProxy: EventLoopProxy<T>;
371
372  /// Creates a new webview runtime. Must be used on the main thread.
373  fn new(args: RuntimeInitArgs) -> Result<Self>;
374
375  /// Creates a new webview runtime on any thread.
376  #[cfg(any(windows, target_os = "linux"))]
377  #[cfg_attr(docsrs, doc(cfg(any(windows, target_os = "linux"))))]
378  fn new_any_thread(args: RuntimeInitArgs) -> Result<Self>;
379
380  /// Creates an `EventLoopProxy` that can be used to dispatch user events to the main event loop.
381  fn create_proxy(&self) -> Self::EventLoopProxy;
382
383  /// Gets a runtime handle.
384  fn handle(&self) -> Self::Handle;
385
386  /// Create a new window.
387  fn create_window<F: Fn(RawWindow) + Send + 'static>(
388    &self,
389    pending: PendingWindow<T, Self>,
390    after_window_creation: Option<F>,
391  ) -> Result<DetachedWindow<T, Self>>;
392
393  /// Create a new webview.
394  fn create_webview(
395    &self,
396    window_id: WindowId,
397    pending: PendingWebview<T, Self>,
398  ) -> Result<DetachedWebview<T, Self>>;
399
400  fn primary_monitor(&self) -> Option<Monitor>;
401  fn monitor_from_point(&self, x: f64, y: f64) -> Option<Monitor>;
402  fn available_monitors(&self) -> Vec<Monitor>;
403
404  fn cursor_position(&self) -> Result<PhysicalPosition<f64>>;
405
406  fn set_theme(&self, theme: Option<Theme>);
407
408  /// Sets the activation policy for the application.
409  #[cfg(target_os = "macos")]
410  #[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
411  fn set_activation_policy(&mut self, activation_policy: ActivationPolicy);
412
413  /// Shows the application, but does not automatically focus it.
414  #[cfg(target_os = "macos")]
415  #[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
416  fn show(&self);
417
418  /// Hides the application.
419  #[cfg(target_os = "macos")]
420  #[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
421  fn hide(&self);
422
423  /// Change the device event filter mode.
424  ///
425  /// Since the DeviceEvent capture can lead to high CPU usage for unfocused windows, [`tao`]
426  /// will ignore them by default for unfocused windows on Windows. This method allows changing
427  /// the filter to explicitly capture them again.
428  ///
429  /// ## Platform-specific
430  ///
431  /// - ** Linux / macOS / iOS / Android**: Unsupported.
432  ///
433  /// [`tao`]: https://crates.io/crates/tao
434  fn set_device_event_filter(&mut self, filter: DeviceEventFilter);
435
436  /// Runs an iteration of the runtime event loop and returns control flow to the caller.
437  #[cfg(desktop)]
438  fn run_iteration<F: FnMut(RunEvent<T>) + 'static>(&mut self, callback: F);
439
440  /// Run the webview runtime.
441  fn run<F: FnMut(RunEvent<T>) + 'static>(self, callback: F);
442}
443
444/// Webview dispatcher. A thread-safe handle to the webview APIs.
445pub trait WebviewDispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static {
446  /// The runtime this [`WebviewDispatch`] runs under.
447  type Runtime: Runtime<T>;
448
449  /// Run a task on the main thread.
450  fn run_on_main_thread<F: FnOnce() + Send + 'static>(&self, f: F) -> Result<()>;
451
452  /// Registers a webview event handler.
453  fn on_webview_event<F: Fn(&WebviewEvent) + Send + 'static>(&self, f: F) -> WebviewEventId;
454
455  /// Runs a closure with the platform webview object as argument.
456  fn with_webview<F: FnOnce(Box<dyn std::any::Any>) + Send + 'static>(&self, f: F) -> Result<()>;
457
458  /// Open the web inspector which is usually called devtools.
459  #[cfg(any(debug_assertions, feature = "devtools"))]
460  fn open_devtools(&self);
461
462  /// Close the web inspector which is usually called devtools.
463  #[cfg(any(debug_assertions, feature = "devtools"))]
464  fn close_devtools(&self);
465
466  /// Gets the devtools window's current open state.
467  #[cfg(any(debug_assertions, feature = "devtools"))]
468  fn is_devtools_open(&self) -> Result<bool>;
469
470  // GETTERS
471
472  /// Returns the webview's current URL.
473  fn url(&self) -> Result<String>;
474
475  /// Returns the webview's bounds.
476  fn bounds(&self) -> Result<Rect>;
477
478  /// Returns the position of the top-left hand corner of the webviews's client area relative to the top-left hand corner of the window.
479  fn position(&self) -> Result<PhysicalPosition<i32>>;
480
481  /// Returns the physical size of the webviews's client area.
482  fn size(&self) -> Result<PhysicalSize<u32>>;
483
484  // SETTER
485
486  /// Navigate to the given URL.
487  fn navigate(&self, url: Url) -> Result<()>;
488
489  /// Opens the dialog to prints the contents of the webview.
490  fn print(&self) -> Result<()>;
491
492  /// Closes the webview.
493  fn close(&self) -> Result<()>;
494
495  /// Sets the webview's bounds.
496  fn set_bounds(&self, bounds: Rect) -> Result<()>;
497
498  /// Resizes the webview.
499  fn set_size(&self, size: Size) -> Result<()>;
500
501  /// Updates the webview position.
502  fn set_position(&self, position: Position) -> Result<()>;
503
504  /// Bring the window to front and focus the webview.
505  fn set_focus(&self) -> Result<()>;
506
507  /// Hide the webview
508  fn hide(&self) -> Result<()>;
509
510  /// Show the webview
511  fn show(&self) -> Result<()>;
512
513  /// Executes javascript on the window this [`WindowDispatch`] represents.
514  fn eval_script<S: Into<String>>(&self, script: S) -> Result<()>;
515
516  /// Moves the webview to the given window.
517  fn reparent(&self, window_id: WindowId) -> Result<()>;
518
519  /// Sets whether the webview should automatically grow and shrink its size and position when the parent window resizes.
520  fn set_auto_resize(&self, auto_resize: bool) -> Result<()>;
521
522  /// Set the webview zoom level
523  fn set_zoom(&self, scale_factor: f64) -> Result<()>;
524
525  /// Set the webview background.
526  fn set_background_color(&self, color: Option<Color>) -> Result<()>;
527
528  /// Clear all browsing data for this webview.
529  fn clear_all_browsing_data(&self) -> Result<()>;
530}
531
532/// Window dispatcher. A thread-safe handle to the window APIs.
533pub trait WindowDispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static {
534  /// The runtime this [`WindowDispatch`] runs under.
535  type Runtime: Runtime<T>;
536
537  /// The window builder type.
538  type WindowBuilder: WindowBuilder;
539
540  /// Run a task on the main thread.
541  fn run_on_main_thread<F: FnOnce() + Send + 'static>(&self, f: F) -> Result<()>;
542
543  /// Registers a window event handler.
544  fn on_window_event<F: Fn(&WindowEvent) + Send + 'static>(&self, f: F) -> WindowEventId;
545
546  // GETTERS
547
548  /// Returns the scale factor that can be used to map logical pixels to physical pixels, and vice versa.
549  fn scale_factor(&self) -> Result<f64>;
550
551  /// Returns the position of the top-left hand corner of the window's client area relative to the top-left hand corner of the desktop.
552  fn inner_position(&self) -> Result<PhysicalPosition<i32>>;
553
554  /// Returns the position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.
555  fn outer_position(&self) -> Result<PhysicalPosition<i32>>;
556
557  /// Returns the physical size of the window's client area.
558  ///
559  /// The client area is the content of the window, excluding the title bar and borders.
560  fn inner_size(&self) -> Result<PhysicalSize<u32>>;
561
562  /// Returns the physical size of the entire window.
563  ///
564  /// These dimensions include the title bar and borders. If you don't want that (and you usually don't), use inner_size instead.
565  fn outer_size(&self) -> Result<PhysicalSize<u32>>;
566
567  /// Gets the window's current fullscreen state.
568  fn is_fullscreen(&self) -> Result<bool>;
569
570  /// Gets the window's current minimized state.
571  fn is_minimized(&self) -> Result<bool>;
572
573  /// Gets the window's current maximized state.
574  fn is_maximized(&self) -> Result<bool>;
575
576  /// Gets the window's current focus state.
577  fn is_focused(&self) -> Result<bool>;
578
579  /// Gets the window's current decoration state.
580  fn is_decorated(&self) -> Result<bool>;
581
582  /// Gets the window's current resizable state.
583  fn is_resizable(&self) -> Result<bool>;
584
585  /// Gets the window's native maximize button state.
586  ///
587  /// ## Platform-specific
588  ///
589  /// - **Linux / iOS / Android:** Unsupported.
590  fn is_maximizable(&self) -> Result<bool>;
591
592  /// Gets the window's native minimize button state.
593  ///
594  /// ## Platform-specific
595  ///
596  /// - **Linux / iOS / Android:** Unsupported.
597  fn is_minimizable(&self) -> Result<bool>;
598
599  /// Gets the window's native close button state.
600  ///
601  /// ## Platform-specific
602  ///
603  /// - **iOS / Android:** Unsupported.
604  fn is_closable(&self) -> Result<bool>;
605
606  /// Gets the window's current visibility state.
607  fn is_visible(&self) -> Result<bool>;
608
609  /// Whether the window is enabled or disable.
610  fn is_enabled(&self) -> Result<bool>;
611
612  /// Gets the window's current title.
613  fn title(&self) -> Result<String>;
614
615  /// Returns the monitor on which the window currently resides.
616  ///
617  /// Returns None if current monitor can't be detected.
618  fn current_monitor(&self) -> Result<Option<Monitor>>;
619
620  /// Returns the primary monitor of the system.
621  ///
622  /// Returns None if it can't identify any monitor as a primary one.
623  fn primary_monitor(&self) -> Result<Option<Monitor>>;
624
625  /// Returns the monitor that contains the given point.
626  fn monitor_from_point(&self, x: f64, y: f64) -> Result<Option<Monitor>>;
627
628  /// Returns the list of all the monitors available on the system.
629  fn available_monitors(&self) -> Result<Vec<Monitor>>;
630
631  /// Returns the `ApplicationWindow` from gtk crate that is used by this window.
632  #[cfg(any(
633    target_os = "linux",
634    target_os = "dragonfly",
635    target_os = "freebsd",
636    target_os = "netbsd",
637    target_os = "openbsd"
638  ))]
639  fn gtk_window(&self) -> Result<gtk::ApplicationWindow>;
640
641  /// Returns the vertical [`gtk::Box`] that is added by default as the sole child of this window.
642  #[cfg(any(
643    target_os = "linux",
644    target_os = "dragonfly",
645    target_os = "freebsd",
646    target_os = "netbsd",
647    target_os = "openbsd"
648  ))]
649  fn default_vbox(&self) -> Result<gtk::Box>;
650
651  /// Raw window handle.
652  fn window_handle(
653    &self,
654  ) -> std::result::Result<raw_window_handle::WindowHandle<'_>, raw_window_handle::HandleError>;
655
656  /// Returns the current window theme.
657  fn theme(&self) -> Result<Theme>;
658
659  // SETTERS
660
661  /// Centers the window.
662  fn center(&self) -> Result<()>;
663
664  /// Requests user attention to the window.
665  ///
666  /// Providing `None` will unset the request for user attention.
667  fn request_user_attention(&self, request_type: Option<UserAttentionType>) -> Result<()>;
668
669  /// Create a new window.
670  fn create_window<F: Fn(RawWindow) + Send + 'static>(
671    &mut self,
672    pending: PendingWindow<T, Self::Runtime>,
673    after_window_creation: Option<F>,
674  ) -> Result<DetachedWindow<T, Self::Runtime>>;
675
676  /// Create a new webview.
677  fn create_webview(
678    &mut self,
679    pending: PendingWebview<T, Self::Runtime>,
680  ) -> Result<DetachedWebview<T, Self::Runtime>>;
681
682  /// Updates the window resizable flag.
683  fn set_resizable(&self, resizable: bool) -> Result<()>;
684
685  /// Enable or disable the window.
686  ///
687  /// ## Platform-specific
688  ///
689  /// - **Android / iOS**: Unsupported.
690  fn set_enabled(&self, enabled: bool) -> Result<()>;
691
692  /// Updates the window's native maximize button state.
693  ///
694  /// ## Platform-specific
695  ///
696  /// - **macOS:** Disables the "zoom" button in the window titlebar, which is also used to enter fullscreen mode.
697  /// - **Linux / iOS / Android:** Unsupported.
698  fn set_maximizable(&self, maximizable: bool) -> Result<()>;
699
700  /// Updates the window's native minimize button state.
701  ///
702  /// ## Platform-specific
703  ///
704  /// - **Linux / iOS / Android:** Unsupported.
705  fn set_minimizable(&self, minimizable: bool) -> Result<()>;
706
707  /// Updates the window's native close button state.
708  ///
709  /// ## Platform-specific
710  ///
711  /// - **Linux:** "GTK+ will do its best to convince the window manager not to show a close button.
712  ///   Depending on the system, this function may not have any effect when called on a window that is already visible"
713  /// - **iOS / Android:** Unsupported.
714  fn set_closable(&self, closable: bool) -> Result<()>;
715
716  /// Updates the window title.
717  fn set_title<S: Into<String>>(&self, title: S) -> Result<()>;
718
719  /// Maximizes the window.
720  fn maximize(&self) -> Result<()>;
721
722  /// Unmaximizes the window.
723  fn unmaximize(&self) -> Result<()>;
724
725  /// Minimizes the window.
726  fn minimize(&self) -> Result<()>;
727
728  /// Unminimizes the window.
729  fn unminimize(&self) -> Result<()>;
730
731  /// Shows the window.
732  fn show(&self) -> Result<()>;
733
734  /// Hides the window.
735  fn hide(&self) -> Result<()>;
736
737  /// Closes the window.
738  fn close(&self) -> Result<()>;
739
740  /// Destroys the window.
741  fn destroy(&self) -> Result<()>;
742
743  /// Updates the decorations flag.
744  fn set_decorations(&self, decorations: bool) -> Result<()>;
745
746  /// Updates the shadow flag.
747  fn set_shadow(&self, enable: bool) -> Result<()>;
748
749  /// Updates the window alwaysOnBottom flag.
750  fn set_always_on_bottom(&self, always_on_bottom: bool) -> Result<()>;
751
752  /// Updates the window alwaysOnTop flag.
753  fn set_always_on_top(&self, always_on_top: bool) -> Result<()>;
754
755  /// Updates the window visibleOnAllWorkspaces flag.
756  fn set_visible_on_all_workspaces(&self, visible_on_all_workspaces: bool) -> Result<()>;
757
758  /// Set the window background.
759  fn set_background_color(&self, color: Option<Color>) -> Result<()>;
760
761  /// Prevents the window contents from being captured by other apps.
762  fn set_content_protected(&self, protected: bool) -> Result<()>;
763
764  /// Resizes the window.
765  fn set_size(&self, size: Size) -> Result<()>;
766
767  /// Updates the window min inner size.
768  fn set_min_size(&self, size: Option<Size>) -> Result<()>;
769
770  /// Updates the window max inner size.
771  fn set_max_size(&self, size: Option<Size>) -> Result<()>;
772
773  /// Sets this window's minimum inner width.
774  fn set_size_constraints(&self, constraints: WindowSizeConstraints) -> Result<()>;
775
776  /// Updates the window position.
777  fn set_position(&self, position: Position) -> Result<()>;
778
779  /// Updates the window fullscreen state.
780  fn set_fullscreen(&self, fullscreen: bool) -> Result<()>;
781
782  /// Bring the window to front and focus.
783  fn set_focus(&self) -> Result<()>;
784
785  /// Updates the window icon.
786  fn set_icon(&self, icon: Icon) -> Result<()>;
787
788  /// Whether to hide the window icon from the taskbar or not.
789  fn set_skip_taskbar(&self, skip: bool) -> Result<()>;
790
791  /// Grabs the cursor, preventing it from leaving the window.
792  ///
793  /// There's no guarantee that the cursor will be hidden. You should
794  /// hide it by yourself if you want so.
795  fn set_cursor_grab(&self, grab: bool) -> Result<()>;
796
797  /// Modifies the cursor's visibility.
798  ///
799  /// If `false`, this will hide the cursor. If `true`, this will show the cursor.
800  fn set_cursor_visible(&self, visible: bool) -> Result<()>;
801
802  // Modifies the cursor icon of the window.
803  fn set_cursor_icon(&self, icon: CursorIcon) -> Result<()>;
804
805  /// Changes the position of the cursor in window coordinates.
806  fn set_cursor_position<Pos: Into<Position>>(&self, position: Pos) -> Result<()>;
807
808  /// Ignores the window cursor events.
809  fn set_ignore_cursor_events(&self, ignore: bool) -> Result<()>;
810
811  /// Starts dragging the window.
812  fn start_dragging(&self) -> Result<()>;
813
814  /// Starts resize-dragging the window.
815  fn start_resize_dragging(&self, direction: ResizeDirection) -> Result<()>;
816
817  /// Sets the badge count on the taskbar
818  /// The badge count appears as a whole for the application
819  /// Using `0` or using `None` will remove the badge
820  ///
821  /// ## Platform-specific
822  /// - **Windows:** Unsupported, use [`WindowDispatch::set_overlay_icon`] instead.
823  /// - **Android:** Unsupported.
824  /// - **iOS:** iOS expects i32, if the value is larger than i32::MAX, it will be clamped to i32::MAX.
825  fn set_badge_count(&self, count: Option<i64>, desktop_filename: Option<String>) -> Result<()>;
826
827  /// Sets the badge count on the taskbar **macOS only**. Using `None` will remove the badge
828  fn set_badge_label(&self, label: Option<String>) -> Result<()>;
829
830  /// Sets the overlay icon on the taskbar **Windows only**. Using `None` will remove the icon
831  ///
832  /// The overlay icon can be unique for each window.
833  fn set_overlay_icon(&self, icon: Option<Icon>) -> Result<()>;
834
835  /// Sets the taskbar progress state.
836  ///
837  /// ## Platform-specific
838  ///
839  /// - **Linux / macOS**: Progress bar is app-wide and not specific to this window. Only supported desktop environments with `libunity` (e.g. GNOME).
840  /// - **iOS / Android:** Unsupported.
841  fn set_progress_bar(&self, progress_state: ProgressBarState) -> Result<()>;
842
843  /// Sets the title bar style. Available on macOS only.
844  ///
845  /// ## Platform-specific
846  ///
847  /// - **Linux / Windows / iOS / Android:** Unsupported.
848  fn set_title_bar_style(&self, style: tauri_utils::TitleBarStyle) -> Result<()>;
849
850  /// Sets the theme for this window.
851  ///
852  /// ## Platform-specific
853  ///
854  /// - **Linux / macOS**: Theme is app-wide and not specific to this window.
855  /// - **iOS / Android:** Unsupported.
856  fn set_theme(&self, theme: Option<Theme>) -> Result<()>;
857}