Skip to content

Commit 2032228

Browse files
authored
refactor!: remove GlobalWindowEvent type (#8430)
* refactor!: remove `GlobalWindowEvent` type * takee references instead
1 parent a9b87c0 commit 2032228

File tree

4 files changed

+12
-34
lines changed

4 files changed

+12
-34
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': 'major:breaking'
3+
---
4+
5+
Removed `GlobalWindowEvent` struct, and unpacked its field to be passed directly to `tauri::Builder::on_window_event`.

core/tauri/src/app.rs

+4-24
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub(crate) type GlobalMenuEventListener<T> = Box<dyn Fn(&T, crate::menu::MenuEve
6363
#[cfg(all(desktop, feature = "tray-icon"))]
6464
pub(crate) type GlobalTrayIconEventListener<T> =
6565
Box<dyn Fn(&T, crate::tray::TrayIconEvent) + Send + Sync>;
66-
pub(crate) type GlobalWindowEventListener<R> = Box<dyn Fn(GlobalWindowEvent<R>) + Send + Sync>;
66+
pub(crate) type GlobalWindowEventListener<R> = Box<dyn Fn(&Window<R>, &WindowEvent) + Send + Sync>;
6767
/// A closure that is run when the Tauri application is setting up.
6868
pub type SetupHook<R> =
6969
Box<dyn FnOnce(&mut App<R>) -> Result<(), Box<dyn std::error::Error>> + Send>;
@@ -219,26 +219,6 @@ impl From<EventLoopMessage> for RunEvent {
219219
}
220220
}
221221

222-
/// A window event that was triggered on the specified window.
223-
#[default_runtime(crate::Wry, wry)]
224-
#[derive(Debug)]
225-
pub struct GlobalWindowEvent<R: Runtime> {
226-
pub(crate) event: WindowEvent,
227-
pub(crate) window: Window<R>,
228-
}
229-
230-
impl<R: Runtime> GlobalWindowEvent<R> {
231-
/// The event payload.
232-
pub fn event(&self) -> &WindowEvent {
233-
&self.event
234-
}
235-
236-
/// The window that the event belongs to.
237-
pub fn window(&self) -> &Window<R> {
238-
&self.window
239-
}
240-
}
241-
242222
/// The asset resolver is a helper to access the [`tauri_utils::assets::Assets`] interface.
243223
#[derive(Debug, Clone)]
244224
pub struct AssetResolver<R: Runtime> {
@@ -1304,18 +1284,18 @@ impl<R: Runtime> Builder<R> {
13041284
/// # Examples
13051285
/// ```
13061286
/// tauri::Builder::default()
1307-
/// .on_window_event(|event| match event.event() {
1287+
/// .on_window_event(|window, event| match event {
13081288
/// tauri::WindowEvent::Focused(focused) => {
13091289
/// // hide window whenever it loses focus
13101290
/// if !focused {
1311-
/// event.window().hide().unwrap();
1291+
/// window.hide().unwrap();
13121292
/// }
13131293
/// }
13141294
/// _ => {}
13151295
/// });
13161296
/// ```
13171297
#[must_use]
1318-
pub fn on_window_event<F: Fn(GlobalWindowEvent<R>) + Send + Sync + 'static>(
1298+
pub fn on_window_event<F: Fn(&Window<R>, &WindowEvent) + Send + Sync + 'static>(
13191299
mut self,
13201300
handler: F,
13211301
) -> Self {

core/tauri/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,7 @@ pub use self::utils::TitleBarStyle;
198198

199199
pub use self::event::{Event, EventId};
200200
pub use {
201-
self::app::{
202-
App, AppHandle, AssetResolver, Builder, CloseRequestApi, GlobalWindowEvent, RunEvent,
203-
WindowEvent,
204-
},
201+
self::app::{App, AppHandle, AssetResolver, Builder, CloseRequestApi, RunEvent, WindowEvent},
205202
self::manager::Asset,
206203
self::runtime::{
207204
webview::WebviewAttributes,

core/tauri/src/manager/window.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ use crate::{
2828
ipc::{InvokeHandler, InvokeResponder},
2929
pattern::PatternJavascript,
3030
window::PageLoadPayload,
31-
AppHandle, EventLoopMessage, GlobalWindowEvent, Icon, Manager, Runtime, Scopes, Window,
32-
WindowEvent,
31+
AppHandle, EventLoopMessage, Icon, Manager, Runtime, Scopes, Window, WindowEvent,
3332
};
3433

3534
use super::AppManager;
@@ -574,10 +573,7 @@ impl<R: Runtime> WindowManager<R> {
574573
window.on_window_event(move |event| {
575574
let _ = on_window_event(&window_, &manager, event);
576575
for handler in window_event_listeners.iter() {
577-
handler(GlobalWindowEvent {
578-
window: window_.clone(),
579-
event: event.clone(),
580-
});
576+
handler(&window_, event);
581577
}
582578
});
583579

0 commit comments

Comments
 (0)