Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changes/WebviewWindow-on_webview_event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
tauri: minor:enhance
---

- Implemented `Webview::on_webview_event` for `WebviewWindow` as well
- Implemented `AsRef<Window<R>>` for `WebviewWindow<R>`

This can be considered a *BREAKING CHANGE* in very specific cases:
Typically, this means you are relying on implicit type inference, such as `let webview: _ = WebviewWindow.as_ref()`.
To resolve this, you should explicitly specify the type, for example `let webview: &Window<R> = WebviewWindow.as_ref()`
or `let webview: _ = AsRef::<Webview<R>>::as_ref(&WebviewWindow)`.
2 changes: 1 addition & 1 deletion crates/tauri/src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ impl<R: Runtime> Webview<R> {
self.use_https_scheme
}

/// Registers a window event listener.
/// Registers a webview event listener.
pub fn on_webview_event<F: Fn(&WebviewEvent) + Send + 'static>(&self, f: F) {
self
.webview
Expand Down
15 changes: 13 additions & 2 deletions crates/tauri/src/webview/webview_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::{
ipc::{CommandArg, CommandItem, InvokeError, OwnedInvokeResponder},
manager::AppManager,
sealed::{ManagerBase, RuntimeOrDispatch},
webview::{Cookie, PageLoadPayload, WebviewBuilder},
webview::{Cookie, PageLoadPayload, WebviewBuilder, WebviewEvent},
window::WindowBuilder,
AppHandle, Event, EventId, Manager, Runtime, Webview, WindowEvent,
};
Expand Down Expand Up @@ -1193,6 +1193,12 @@ impl<R: Runtime> AsRef<Webview<R>> for WebviewWindow<R> {
}
}

impl<R: Runtime> AsRef<Window<R>> for WebviewWindow<R> {
fn as_ref(&self) -> &Window<R> {
&self.window
}
}

impl<R: Runtime> Clone for WebviewWindow<R> {
fn clone(&self) -> Self {
Self {
Expand All @@ -1204,7 +1210,7 @@ impl<R: Runtime> Clone for WebviewWindow<R> {

impl<R: Runtime> Eq for WebviewWindow<R> {}
impl<R: Runtime> PartialEq for WebviewWindow<R> {
/// Only use the [`Window`]'s label to compare equality.
/// Only use the [`Webview`]'s label to compare equality.
fn eq(&self, other: &Self) -> bool {
self.webview.eq(&other.webview)
}
Expand Down Expand Up @@ -1269,6 +1275,11 @@ impl<R: Runtime> WebviewWindow<R> {
self.window.on_window_event(f);
}

/// Registers a webview event listener.
pub fn on_webview_event<F: Fn(&WebviewEvent) + Send + 'static>(&self, f: F) {
self.webview.on_webview_event(f);
}

/// Resolves the given command scope for this webview on the currently loaded URL.
///
/// If the command is not allowed, returns None.
Expand Down
Loading