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