tauri::webview

Struct WebviewWindow

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

A type that wraps a Window together with a Webview.

Implementations§

Source§

impl<R: Runtime> WebviewWindow<R>

Base webview window functions.

Source

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

Initializes a WebviewWindowBuilder with the given window label and webview URL.

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

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 webview label.

Source

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

Registers a window event listener.

Source

pub fn resolve_command_scope<T: ScopeObject>( &self, plugin: &str, command: &str, ) -> Result<Option<ResolvedScope<T>>>

Resolves the given command scope for this webview on the currently loaded URL.

If the command is not allowed, returns None.

If the scope cannot be deserialized to the given type, an error is returned.

In a command context this can be directly resolved from the command arguments via crate::ipc::CommandScope:

use tauri::ipc::CommandScope;

#[derive(Debug, serde::Deserialize)]
struct ScopeType {
  some_value: String,
}
#[tauri::command]
fn my_command(scope: CommandScope<ScopeType>) {
  // check scope
}
§Examples
use tauri::Manager;

#[derive(Debug, serde::Deserialize)]
struct ScopeType {
  some_value: String,
}

tauri::Builder::default()
  .setup(|app| {
    let webview = app.get_webview_window("main").unwrap();
    let scope = webview.resolve_command_scope::<ScopeType>("my-plugin", "read");
    Ok(())
  });
Source§

impl<R: Runtime> WebviewWindow<R>

Menu APIs

Source

pub fn on_menu_event<F: Fn(&Window<R>, MenuEvent) + Send + Sync + 'static>( &self, f: F, )

Registers a global menu event listener.

Note that this handler is called for any menu event, whether it is coming from this window, another window or from the tray icon menu.

Also note that this handler will not be called if the window used to register it was closed.

§Examples
use tauri::menu::{Menu, Submenu, MenuItem};
use tauri::{WebviewWindowBuilder, WebviewUrl};

tauri::Builder::default()
  .setup(|app| {
    let handle = app.handle();
    let save_menu_item = MenuItem::new(handle, "Save", true, None::<&str>)?;
    let menu = Menu::with_items(handle, &[
      &Submenu::with_items(handle, "File", true, &[
        &save_menu_item,
      ])?,
    ])?;
    let webview_window = WebviewWindowBuilder::new(app, "editor", WebviewUrl::default())
      .menu(menu)
      .build()
      .unwrap();

    webview_window.on_menu_event(move |window, event| {
      if event.id == save_menu_item.id() {
          // save menu item
      }
    });

    Ok(())
  });
Source

pub fn menu(&self) -> Option<Menu<R>>

Returns this window menu.

Source

pub fn set_menu(&self, menu: Menu<R>) -> Result<Option<Menu<R>>>

Sets the window menu and returns the previous one.

§Platform-specific:
  • macOS: Unsupported. The menu on macOS is app-wide and not specific to one window, if you need to set it, use AppHandle::set_menu instead.
Source

pub fn remove_menu(&self) -> Result<Option<Menu<R>>>

Removes the window menu and returns it.

§Platform-specific:
  • macOS: Unsupported. The menu on macOS is app-wide and not specific to one window, if you need to remove it, use AppHandle::remove_menu instead.
Source

pub fn hide_menu(&self) -> Result<()>

Hides the window menu.

Source

pub fn show_menu(&self) -> Result<()>

Shows the window menu.

Source

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

Shows the window menu.

Source

pub fn popup_menu<M: ContextMenu>(&self, menu: &M) -> Result<()>

Shows the specified menu as a context menu at the cursor position.

Source

pub fn popup_menu_at<M: ContextMenu, P: Into<Position>>( &self, menu: &M, position: P, ) -> Result<()>

Shows the specified menu as a context menu at the specified position.

The position is relative to the window’s top-left corner.

Source§

impl<R: Runtime> WebviewWindow<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_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 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 monitor_from_point(&self, x: f64, y: f64) -> Result<Option<Monitor>>

Returns the monitor that contains the given point.

Source

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

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

Source

pub fn gtk_window(&self) -> Result<ApplicationWindow>

Returns the ApplicationWindow from gtk crate that is used by this window.

Note that this type can only be used on the main thread.

Source

pub fn default_vbox(&self) -> Result<Box>

Returns the vertical gtk::Box that is added by default as the sole child of this window.

Note that this type can only be used on the main thread.

Source

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

Returns the current window theme.

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

impl<R: Runtime> WebviewWindow<R>

Desktop window getters.

Source

pub fn cursor_position(&self) -> Result<PhysicalPosition<f64>>

Get the cursor position relative to the top-left hand corner of the desktop.

Note that the top-left hand corner of the desktop is not necessarily the same as the screen. If the user uses a desktop with multiple monitors, the top-left hand corner of the desktop is the top-left hand corner of the main monitor on Windows and macOS or the top-left of the leftmost monitor on X11.

The coordinates can be negative if the top-left hand corner of the window is outside of the visible screen region.

Source§

impl<R: Runtime> WebviewWindow<R>

Desktop window setters and actions.

Source

pub fn center(&self) -> Result<()>

Centers the window.

Source

pub fn request_user_attention( &self, request_type: Option<UserAttentionType>, ) -> Result<()>

Requests user attention to the window, this has no effect if the application is already focused. How requesting for user attention manifests is platform dependent, see UserAttentionType for details.

Providing None will unset the request for user attention. Unsetting the request for user attention might not be done automatically by the WM when the window receives input.

§Platform-specific
  • macOS: None has no effect.
  • Linux: Urgency levels have the same effect.
Source

pub fn set_resizable(&self, resizable: bool) -> Result<()>

Determines if this window should be resizable. When resizable is set to false, native window’s maximize button is automatically disabled.

Source

pub fn set_enabled(&self, enabled: bool) -> Result<()>

Enable or disable the window.

Source

pub fn set_maximizable(&self, maximizable: bool) -> Result<()>

Determines if this window’s native maximize button should be enabled. If resizable is set to false, this setting is ignored.

§Platform-specific
  • macOS: Disables the “zoom” button in the window titlebar, which is also used to enter fullscreen mode.
  • Linux / iOS / Android: Unsupported.
Source

pub fn set_minimizable(&self, minimizable: bool) -> Result<()>

Determines if this window’s native minimize button should be enabled.

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

pub fn set_closable(&self, closable: bool) -> Result<()>

Determines if this window’s native close button should be enabled.

§Platform-specific
  • Linux: “GTK+ will do its best to convince the window manager not to show a close button. Depending on the system, this function may not have any effect when called on a window that is already visible”
  • iOS / Android: Unsupported.
Source

pub fn set_title(&self, title: &str) -> Result<()>

Set this window’s title.

Source

pub fn maximize(&self) -> Result<()>

Maximizes this window.

Source

pub fn unmaximize(&self) -> Result<()>

Un-maximizes this window.

Source

pub fn minimize(&self) -> Result<()>

Minimizes this window.

Source

pub fn unminimize(&self) -> Result<()>

Un-minimizes this window.

Source

pub fn show(&self) -> Result<()>

Show this window.

Source

pub fn hide(&self) -> Result<()>

Hide this window.

Source

pub fn close(&self) -> Result<()>

Closes this window. It emits [crate::RunEvent::CloseRequested] first like a user-initiated close request so you can intercept it.

Source

pub fn destroy(&self) -> Result<()>

Destroys this window. Similar to Self::close but does not emit any events and force close the window instead.

Source

pub fn set_decorations(&self, decorations: bool) -> Result<()>

Determines if this window should be decorated.

Source

pub fn set_shadow(&self, enable: bool) -> Result<()>

Determines if this window should have shadow.

§Platform-specific
  • Windows:
    • false has no effect on decorated window, shadow are always ON.
    • true will make undecorated window have a 1px white border, and on Windows 11, it will have a rounded corners.
  • Linux: Unsupported.
Source

pub fn set_effects<E: Into<Option<WindowEffectsConfig>>>( &self, effects: E, ) -> Result<()>

Sets window effects, pass None to clear any effects applied if possible.

Requires the window to be transparent.

See crate::window::EffectsBuilder for a convenient builder for crate::utils::config::WindowEffectsConfig.

use tauri::{Manager, window::{Color, Effect, EffectState, EffectsBuilder}};
tauri::Builder::default()
  .setup(|app| {
    let webview_window = app.get_webview_window("main").unwrap();
    webview_window.set_effects(
      EffectsBuilder::new()
        .effect(Effect::Popover)
        .state(EffectState::Active)
        .radius(5.)
        .color(Color(0, 0, 0, 255))
        .build(),
    )?;
    Ok(())
  });
§Platform-specific:
Source

pub fn set_always_on_bottom(&self, always_on_bottom: bool) -> Result<()>

Determines if this window should always be below other windows.

Source

pub fn set_always_on_top(&self, always_on_top: bool) -> Result<()>

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

Source

pub fn set_visible_on_all_workspaces( &self, visible_on_all_workspaces: bool, ) -> Result<()>

Sets whether the window should be visible on all workspaces or virtual desktops.

Source

pub fn set_content_protected(&self, protected: bool) -> Result<()>

Prevents the window contents from being captured by other apps.

Source

pub fn set_size<S: Into<Size>>(&self, size: S) -> Result<()>

Resizes this window.

Source

pub fn set_min_size<S: Into<Size>>(&self, size: Option<S>) -> Result<()>

Sets this window’s minimum inner size.

Source

pub fn set_max_size<S: Into<Size>>(&self, size: Option<S>) -> Result<()>

Sets this window’s maximum inner size.

Source

pub fn set_size_constraints( &self, constriants: WindowSizeConstraints, ) -> Result<()>

Sets this window’s minimum inner width.

Source

pub fn set_position<Pos: Into<Position>>(&self, position: Pos) -> Result<()>

Sets this window’s position.

Source

pub fn set_fullscreen(&self, fullscreen: bool) -> Result<()>

Determines if this window should be fullscreen.

Source

pub fn set_focus(&self) -> Result<()>

Bring the window to front and focus.

Source

pub fn set_icon(&self, icon: Image<'_>) -> Result<()>

Sets this window’ icon.

Source

pub fn set_background_color(&self, color: Option<Color>) -> Result<()>

Sets the window background color.

§Platform-specific:
  • iOS / Android: Unsupported.
  • macOS: Not implemented for the webview layer..
  • Windows:
    • alpha channel is ignored for the window layer.
    • On Windows 7, transparency is not supported and the alpha value will be ignored for the webview layer..
    • On Windows 8 and newer: translucent colors are not supported so any alpha value other than 0 will be replaced by 255 for the webview layer.
Source

pub fn set_skip_taskbar(&self, skip: bool) -> Result<()>

Whether to hide the window icon from the taskbar or not.

§Platform-specific
  • macOS: Unsupported.
Source

pub fn set_cursor_grab(&self, grab: bool) -> Result<()>

Grabs the cursor, preventing it from leaving the window.

There’s no guarantee that the cursor will be hidden. You should hide it by yourself if you want so.

§Platform-specific
  • Linux: Unsupported.
  • macOS: This locks the cursor in a fixed location, which looks visually awkward.
Source

pub fn set_cursor_visible(&self, visible: bool) -> Result<()>

Modifies the cursor’s visibility.

If false, this will hide the cursor. If true, this will show the cursor.

§Platform-specific
  • Windows: The cursor is only hidden within the confines of the window.
  • macOS: The cursor is hidden as long as the window has input focus, even if the cursor is outside of the window.
Source

pub fn set_cursor_icon(&self, icon: CursorIcon) -> Result<()>

Modifies the cursor icon of the window.

Source

pub fn set_cursor_position<Pos: Into<Position>>( &self, position: Pos, ) -> Result<()>

Changes the position of the cursor in window coordinates.

Source

pub fn set_ignore_cursor_events(&self, ignore: bool) -> Result<()>

Ignores the window cursor events.

Source

pub fn start_dragging(&self) -> Result<()>

Starts dragging the window.

Source

pub fn set_progress_bar(&self, progress_state: ProgressBarState) -> Result<()>

Sets the taskbar progress state.

§Platform-specific
  • Linux / macOS: Progress bar is app-wide and not specific to this window.
  • Linux: Only supported desktop environments with libunity (e.g. GNOME).
  • iOS / Android: Unsupported.
Source

pub fn set_title_bar_style(&self, style: TitleBarStyle) -> Result<()>

Sets the title bar style. macOS only.

Source

pub fn set_theme(&self, theme: Option<Theme>) -> Result<()>

Set the window theme.

Source§

impl<R: Runtime> WebviewWindow<R>

Desktop webview setters and actions.

Source

pub fn print(&self) -> Result<()>

Opens the dialog to prints the contents of the webview. Currently only supported on macOS on wry. window.print() works on all platforms.

Source§

impl<R: Runtime> WebviewWindow<R>

Webview APIs.

Source

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

Executes a closure, providing it with the webview handle that is specific to the current platform.

The closure is executed on the main thread.

§Examples
use tauri::Manager;

fn main() {
  tauri::Builder::default()
    .setup(|app| {
      let main_webview = app.get_webview_window("main").unwrap();
      main_webview.with_webview(|webview| {
        #[cfg(target_os = "linux")]
        {
          // see <https://docs.rs/webkit2gtk/2.0.0/webkit2gtk/struct.WebView.html>
          // and <https://docs.rs/webkit2gtk/2.0.0/webkit2gtk/trait.WebViewExt.html>
          use webkit2gtk::WebViewExt;
          webview.inner().set_zoom_level(4.);
        }

        #[cfg(windows)]
        unsafe {
          // see <https://docs.rs/webview2-com/0.19.1/webview2_com/Microsoft/Web/WebView2/Win32/struct.ICoreWebView2Controller.html>
          webview.controller().SetZoomFactor(4.).unwrap();
        }

        #[cfg(target_os = "macos")]
        unsafe {
          let view: &objc2_web_kit::WKWebView = &*webview.inner().cast();
          let controller: &objc2_web_kit::WKUserContentController = &*webview.controller().cast();
          let window: &objc2_app_kit::NSWindow = &*webview.ns_window().cast();

          view.setPageZoom(4.);
          controller.removeAllUserScripts();
          let bg_color = objc2_app_kit::NSColor::colorWithDeviceRed_green_blue_alpha(0.5, 0.2, 0.4, 1.);
          window.setBackgroundColor(Some(&bg_color));
        }

        #[cfg(target_os = "android")]
        {
          use jni::objects::JValue;
          webview.jni_handle().exec(|env, _, webview| {
            env.call_method(webview, "zoomBy", "(F)V", &[JValue::Float(4.)]).unwrap();
          })
        }
      });
      Ok(())
  });
}
Source

pub fn url(&self) -> Result<Url>

Returns the current url of the webview.

Source

pub fn navigate(&mut self, url: Url) -> Result<()>

Navigates the webview to the defined url.

Source

pub fn on_message( self, request: InvokeRequest, responder: Box<OwnedInvokeResponder<R>>, )

Handles this window receiving an crate::webview::InvokeRequest.

Source

pub fn eval(&self, js: &str) -> Result<()>

Evaluates JavaScript on this window.

Source

pub fn open_devtools(&self)

Available on debug-assertions enabled or crate feature devtools only.

Opens the developer tools window (Web Inspector). The devtools is only enabled on debug builds or with the devtools feature flag.

§Platform-specific
  • macOS: Only supported on macOS 10.15+. This is a private API on macOS, so you cannot use this if your application will be published on the App Store.
§Examples
use tauri::Manager;
tauri::Builder::default()
  .setup(|app| {
    #[cfg(debug_assertions)]
    app.get_webview_window("main").unwrap().open_devtools();
    Ok(())
  });
Source

pub fn close_devtools(&self)

Available on debug-assertions enabled or crate feature devtools only.

Closes the developer tools window (Web Inspector). The devtools is only enabled on debug builds or with the devtools feature flag.

§Platform-specific
  • macOS: Only supported on macOS 10.15+. This is a private API on macOS, so you cannot use this if your application will be published on the App Store.
  • Windows: Unsupported.
§Examples
use tauri::Manager;
tauri::Builder::default()
  .setup(|app| {
    #[cfg(debug_assertions)]
    {
      let webview = app.get_webview_window("main").unwrap();
      webview.open_devtools();
      std::thread::spawn(move || {
        std::thread::sleep(std::time::Duration::from_secs(10));
        webview.close_devtools();
      });
    }
    Ok(())
  });
Source

pub fn is_devtools_open(&self) -> bool

Available on debug-assertions enabled or crate feature devtools only.

Checks if the developer tools window (Web Inspector) is opened. The devtools is only enabled on debug builds or with the devtools feature flag.

§Platform-specific
  • macOS: Only supported on macOS 10.15+. This is a private API on macOS, so you cannot use this if your application will be published on the App Store.
  • Windows: Unsupported.
§Examples
use tauri::Manager;
tauri::Builder::default()
  .setup(|app| {
    #[cfg(debug_assertions)]
    {
      let webview = app.get_webview_window("main").unwrap();
      if !webview.is_devtools_open() {
        webview.open_devtools();
      }
    }
    Ok(())
  });
Source

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

Set the webview zoom level

§Platform-specific:
  • Android: Not supported.
  • macOS: available on macOS 11+ only.
  • iOS: available on iOS 14+ only.
Source

pub fn clear_all_browsing_data(&self) -> Result<()>

Clear all browsing data for this webview window.

Trait Implementations§

Source§

impl<R: Runtime> AsRef<Webview<R>> for WebviewWindow<R>

Source§

fn as_ref(&self) -> &Webview<R>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

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

Source§

fn clone(&self) -> Self

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

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

Performs copy-assignment from source. Read more
Source§

impl<'de, R: Runtime> CommandArg<'de, R> for WebviewWindow<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: Debug + Runtime> Debug for WebviewWindow<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 WebviewWindow<R>

Source§

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

Emits an event to all targets.

§Examples
use tauri::Emitter;

#[tauri::command]
fn synchronize(window: tauri::WebviewWindow) {
  // emits the synchronized event to all webviews
  window.emit("synchronized", ());
}
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.

§Examples
use tauri::{Emitter, EventTarget};

#[tauri::command]
fn download(window: tauri::WebviewWindow) {
  for i in 1..100 {
    std::thread::sleep(std::time::Duration::from_millis(150));
    // emit a download progress event to all listeners
    window.emit_to(EventTarget::any(), "download-progress", i);
    // emit an event to listeners that used App::listen or AppHandle::listen
    window.emit_to(EventTarget::app(), "download-progress", i);
    // emit an event to any webview/window/webviewWindow matching the given label
    window.emit_to("updater", "download-progress", i); // similar to using EventTarget::labeled
    window.emit_to(EventTarget::labeled("updater"), "download-progress", i);
    // emit an event to listeners that used WebviewWindow::listen
    window.emit_to(EventTarget::webview_window("updater"), "download-progress", i);
  }
}
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.

§Examples
use tauri::{Emitter, EventTarget};

#[tauri::command]
fn download(window: tauri::WebviewWindow) {
  for i in 1..100 {
    std::thread::sleep(std::time::Duration::from_millis(150));
    // emit a download progress event to the updater window
    window.emit_filter("download-progress", i, |t| match t {
      EventTarget::WebviewWindow { label } => label == "main",
      _ => false,
    });
  }
}
Source§

impl<R: Runtime> FunctionArg for WebviewWindow<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 WebviewWindow<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 WebviewWindow<R>

Source§

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

Get a handle to the window.
Source§

impl<R: Runtime> Listener<R> for WebviewWindow<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 webview window.

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

tauri::Builder::default()
  .setup(|app| {
    let webview_window = app.get_webview_window("main").unwrap();
    webview_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 webview only once.

See Self::listen for more information.

Source§

fn unlisten(&self, id: EventId)

Unlisten to an event on this webview window.

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

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

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

    // stop listening to the event when you do not need it anymore
    webview_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 WebviewWindow<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,

Removes the state managed by the application for T. Returns the state if it was actually removed.
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§

fn add_capability(&self, capability: impl RuntimeCapability) -> Result<()>

Adds a capability to the app. Read more
Source§

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

Source§

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

Only use the Window’s label to compare equality.

1.0.0 · Source§

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 WebviewWindow<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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<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> 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> MaybeSendSync for T

Source§

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