Struct Window

Source
pub struct Window<R: Runtime = Wry> { /* private fields */ }
Expand description

A window managed by Tauri.

This type also implements Manager which allows you to manage other windows attached to the same application.

Implementations§

Source§

impl<R: Runtime> Window<R>

Base window functions.

Source

pub fn builder<M: Manager<R>, L: Into<String>>( manager: &M, label: L, ) -> WindowBuilder<'_, R, M>

Available on crate feature unstable only.

Initializes a window builder with the given window label.

Data URLs are only supported with the webview-data-url feature flag.

Source

pub fn webviews(&self) -> Vec<Webview<R>>

List of webviews associated with this window.

Source

pub fn run_on_main_thread<F: FnOnce() + Send + 'static>( &self, f: F, ) -> Result<()>

Runs the given closure on the main thread.

Source

pub fn label(&self) -> &str

The label of this window.

Source

pub fn on_window_event<F: Fn(&WindowEvent) + Send + 'static>(&self, f: F)

Registers a window event listener.

Source§

impl<R: Runtime> Window<R>

Window getters.

Source

pub fn scale_factor(&self) -> Result<f64>

Returns the scale factor that can be used to map logical pixels to physical pixels, and vice versa.

Source

pub fn inner_position(&self) -> Result<PhysicalPosition<i32>>

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.

Source

pub fn outer_position(&self) -> Result<PhysicalPosition<i32>>

Returns the position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.

Source

pub fn inner_size(&self) -> Result<PhysicalSize<u32>>

Returns the physical size of the window’s client area.

The client area is the content of the window, excluding the title bar and borders.

Source

pub fn outer_size(&self) -> Result<PhysicalSize<u32>>

Returns the physical size of the entire window.

These dimensions include the title bar and borders. If you don’t want that (and you usually don’t), use inner_size instead.

Source

pub fn is_fullscreen(&self) -> Result<bool>

Gets the window’s current fullscreen state.

Source

pub fn is_minimized(&self) -> Result<bool>

Gets the window’s current minimized state.

Source

pub fn is_maximized(&self) -> Result<bool>

Gets the window’s current maximized state.

Source

pub fn is_focused(&self) -> Result<bool>

Gets the window’s current focus state.

Source

pub fn is_decorated(&self) -> Result<bool>

Gets the window’s current decoration state.

Source

pub fn is_resizable(&self) -> Result<bool>

Gets the window’s current resizable state.

Source

pub fn is_enabled(&self) -> Result<bool>

Whether the window is enabled or disabled.

Source

pub fn is_always_on_top(&self) -> Result<bool>

Determines if this window should always be on top of other windows.

§Platform-specific
  • iOS / Android: Unsupported.
Source

pub fn is_maximizable(&self) -> Result<bool>

Gets the window’s native maximize button state

§Platform-specific
  • Linux / iOS / Android: Unsupported.
Source

pub fn is_minimizable(&self) -> Result<bool>

Gets the window’s native minimize button state

§Platform-specific
  • Linux / iOS / Android: Unsupported.
Source

pub fn is_closable(&self) -> Result<bool>

Gets the window’s native close button state

§Platform-specific
  • Linux / iOS / Android: Unsupported.
Source

pub fn is_visible(&self) -> Result<bool>

Gets the window’s current visibility state.

Source

pub fn title(&self) -> Result<String>

Gets the window’s current title.

Source

pub fn current_monitor(&self) -> Result<Option<Monitor>>

Returns the monitor on which the window currently resides.

Returns None if current monitor can’t be detected.

Source

pub fn monitor_from_point(&self, x: f64, y: f64) -> Result<Option<Monitor>>

Returns the monitor that contains the given point.

Source

pub fn primary_monitor(&self) -> Result<Option<Monitor>>

Returns the primary monitor of the system.

Returns None if it can’t identify any monitor as a primary one.

Source

pub fn available_monitors(&self) -> Result<Vec<Monitor>>

Returns the list of all the monitors available on the system.

Source

pub fn theme(&self) -> Result<Theme>

Returns the current window theme.

§Platform-specific
  • macOS: Only supported on macOS 10.14+.

Trait Implementations§

Source§

impl<R: Runtime> Clone for Window<R>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'de, R: Runtime> CommandArg<'de, R> for Window<R>

Source§

fn from_command(command: CommandItem<'de, R>) -> Result<Self, InvokeError>

Grabs the Window from the CommandItem. This will never fail.

Source§

impl<R: Runtime> Debug for Window<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<R: Runtime> Emitter<R> for Window<R>

Source§

fn emit<S: Serialize + Clone>(&self, event: &str, payload: S) -> Result<()>

Emits an event to all targets. Read more
Source§

fn emit_str(&self, event: &str, payload: String) -> Result<()>

Similar to Emitter::emit but the payload is json serialized.
Source§

fn emit_to<I, S>(&self, target: I, event: &str, payload: S) -> Result<()>
where I: Into<EventTarget>, S: Serialize + Clone,

Emits an event to all targets matching the given target. Read more
Source§

fn emit_str_to<I>(&self, target: I, event: &str, payload: String) -> Result<()>
where I: Into<EventTarget>,

Similar to Emitter::emit_to but the payload is json serialized.
Source§

fn emit_filter<S, F>(&self, event: &str, payload: S, filter: F) -> Result<()>
where S: Serialize + Clone, F: Fn(&EventTarget) -> bool,

Emits an event to all targets based on the given filter. Read more
Source§

fn emit_str_filter<F>( &self, event: &str, payload: String, filter: F, ) -> Result<()>
where F: Fn(&EventTarget) -> bool,

Similar to Emitter::emit_filter but the payload is json serialized.
Source§

impl<R: Runtime> FunctionArg for Window<R>

Source§

fn to_datatype(_: &mut TypeMap) -> Option<DataType>

Gets the type of an argument as a DataType. Read more
Source§

impl<R: Runtime> HasDisplayHandle for Window<R>

Source§

fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>

Get a handle to the display controller of the windowing system.
Source§

impl<R: Runtime> HasWindowHandle for Window<R>

Source§

fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>

Get a handle to the window.
Source§

impl<R: Runtime> Hash for Window<R>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Only use the Window’s label to represent its hash.

1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<R: Runtime> Listener<R> for Window<R>

Source§

fn listen<F>(&self, event: impl Into<String>, handler: F) -> EventId
where F: Fn(Event) + Send + 'static,

Listen to an event on this window.

§Examples
use tauri::{Manager, Listener};

tauri::Builder::default()
  .setup(|app| {
    let window = app.get_window("main").unwrap();
    window.listen("component-loaded", move |event| {
      println!("window just loaded a component");
    });

    Ok(())
  });
Source§

fn once<F>(&self, event: impl Into<String>, handler: F) -> EventId
where F: FnOnce(Event) + Send + 'static,

Listen to an event on this window only once.

See Self::listen for more information.

Source§

fn unlisten(&self, id: EventId)

Unlisten to an event on this window.

§Examples
use tauri::{Manager, Listener};

tauri::Builder::default()
  .setup(|app| {
    let window = app.get_window("main").unwrap();
    let window_ = window.clone();
    let handler = window.listen("component-loaded", move |event| {
      println!("window just loaded a component");

      // we no longer need to listen to the event
      // we also could have used `window.once` instead
      window_.unlisten(event.id());
    });

    // stop listening to the event when you do not need it anymore
    window.unlisten(handler);

    Ok(())
  });
Source§

fn listen_any<F>(&self, event: impl Into<String>, handler: F) -> EventId
where F: Fn(Event) + Send + 'static,

Listen to an emitted event to any target. Read more
Source§

fn once_any<F>(&self, event: impl Into<String>, handler: F) -> EventId
where F: FnOnce(Event) + Send + 'static,

Listens once to an emitted event to any target . Read more
Source§

impl<R: Runtime> Manager<R> for Window<R>

Source§

fn resources_table(&self) -> MutexGuard<'_, ResourceTable>

Get a reference to the resources table of this manager.
Source§

fn app_handle(&self) -> &AppHandle<R>

The application handle associated with this manager.
Source§

fn config(&self) -> &Config

The Config the manager was created with.
Source§

fn package_info(&self) -> &PackageInfo

The PackageInfo the manager was created with.
Source§

fn get_window(&self, label: &str) -> Option<Window<R>>

Available on crate feature unstable only.
Fetch a single window from the manager.
Source§

fn get_focused_window(&self) -> Option<Window<R>>

Available on crate feature unstable only.
Fetch the focused window. Returns None if there is not any focused window.
Source§

fn windows(&self) -> HashMap<String, Window<R>>

Available on crate feature unstable only.
Fetch all managed windows.
Source§

fn get_webview(&self, label: &str) -> Option<Webview<R>>

Available on crate feature unstable only.
Fetch a single webview from the manager.
Source§

fn webviews(&self) -> HashMap<String, Webview<R>>

Available on crate feature unstable only.
Fetch all managed webviews.
Source§

fn get_webview_window(&self, label: &str) -> Option<WebviewWindow<R>>

Fetch a single webview window from the manager.
Source§

fn webview_windows(&self) -> HashMap<String, WebviewWindow<R>>

Fetch all managed webview windows.
Source§

fn manage<T>(&self, state: T) -> bool
where T: Send + Sync + 'static,

Add state to the state managed by the application. Read more
Source§

fn unmanage<T>(&self) -> Option<T>
where T: Send + Sync + 'static,

👎Deprecated since 2.3.0: This method is unsafe, since it can cause dangling references.
Removes the state managed by the application for T. Returns the state if it was actually removed. Read more
Source§

fn state<T>(&self) -> State<'_, T>
where T: Send + Sync + 'static,

Retrieves the managed state for the type T. Read more
Source§

fn try_state<T>(&self) -> Option<State<'_, T>>
where T: Send + Sync + 'static,

Attempts to retrieve the managed state for the type T. Read more
Source§

fn env(&self) -> Env

Gets the managed Env.
Source§

fn asset_protocol_scope(&self) -> Scope

Gets the scope for the asset protocol.
Source§

fn path(&self) -> &PathResolver<R>

The path resolver.
Source§

impl<R: Runtime> PartialEq for Window<R>

Source§

fn eq(&self, other: &Self) -> bool

Only use the Window’s label to compare equality.

1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<R: Runtime> Eq for Window<R>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HasRawDisplayHandle for T
where T: HasDisplayHandle + ?Sized,

Source§

fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>

👎Deprecated: Use HasDisplayHandle instead
Source§

impl<T> HasRawWindowHandle for T
where T: HasWindowHandle + ?Sized,

Source§

fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>

👎Deprecated: Use HasWindowHandle instead
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> UserEvent for T
where T: Debug + Clone + Send + 'static,