Skip to content

Commit 7261a14

Browse files
authored
feat: impl AsRef<Window> and on_webview_event for WebviewWindow (#14012)
1 parent 0e6b5cb commit 7261a14

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
tauri: minor:enhance
3+
---
4+
5+
- Implemented `Webview::on_webview_event` for `WebviewWindow` as well
6+
- Implemented `AsRef<Window<R>>` for `WebviewWindow<R>`
7+
8+
This can be considered a *BREAKING CHANGE* in very specific cases:
9+
Typically, this means you are relying on implicit type inference, such as `let webview: _ = WebviewWindow.as_ref()`.
10+
To resolve this, you should explicitly specify the type, for example `let webview: &Window<R> = WebviewWindow.as_ref()`
11+
or `let webview: _ = AsRef::<Webview<R>>::as_ref(&WebviewWindow)`.

crates/tauri/src/webview/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ impl<R: Runtime> Webview<R> {
11211121
self.use_https_scheme
11221122
}
11231123

1124-
/// Registers a window event listener.
1124+
/// Registers a webview event listener.
11251125
pub fn on_webview_event<F: Fn(&WebviewEvent) + Send + 'static>(&self, f: F) {
11261126
self
11271127
.webview

crates/tauri/src/webview/webview_window.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::{
3434
ipc::{CommandArg, CommandItem, InvokeError, OwnedInvokeResponder},
3535
manager::AppManager,
3636
sealed::{ManagerBase, RuntimeOrDispatch},
37-
webview::{Cookie, PageLoadPayload, WebviewBuilder},
37+
webview::{Cookie, PageLoadPayload, WebviewBuilder, WebviewEvent},
3838
window::WindowBuilder,
3939
AppHandle, Event, EventId, Manager, Runtime, Webview, WindowEvent,
4040
};
@@ -1193,6 +1193,12 @@ impl<R: Runtime> AsRef<Webview<R>> for WebviewWindow<R> {
11931193
}
11941194
}
11951195

1196+
impl<R: Runtime> AsRef<Window<R>> for WebviewWindow<R> {
1197+
fn as_ref(&self) -> &Window<R> {
1198+
&self.window
1199+
}
1200+
}
1201+
11961202
impl<R: Runtime> Clone for WebviewWindow<R> {
11971203
fn clone(&self) -> Self {
11981204
Self {
@@ -1204,7 +1210,7 @@ impl<R: Runtime> Clone for WebviewWindow<R> {
12041210

12051211
impl<R: Runtime> Eq for WebviewWindow<R> {}
12061212
impl<R: Runtime> PartialEq for WebviewWindow<R> {
1207-
/// Only use the [`Window`]'s label to compare equality.
1213+
/// Only use the [`Webview`]'s label to compare equality.
12081214
fn eq(&self, other: &Self) -> bool {
12091215
self.webview.eq(&other.webview)
12101216
}
@@ -1269,6 +1275,11 @@ impl<R: Runtime> WebviewWindow<R> {
12691275
self.window.on_window_event(f);
12701276
}
12711277

1278+
/// Registers a webview event listener.
1279+
pub fn on_webview_event<F: Fn(&WebviewEvent) + Send + 'static>(&self, f: F) {
1280+
self.webview.on_webview_event(f);
1281+
}
1282+
12721283
/// Resolves the given command scope for this webview on the currently loaded URL.
12731284
///
12741285
/// If the command is not allowed, returns None.

0 commit comments

Comments
 (0)