Skip to content

Commit

Permalink
fix(core): WindowEvent type used on Window::on_window_event (#3796)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Mar 29, 2022
1 parent 169b503 commit 06aa87b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-on-window-event-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Fixes the `WindowEvent` type used on `Window::on_window_event`.
9 changes: 5 additions & 4 deletions core/tauri/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ use crate::{
ResponseBuilder as HttpResponseBuilder,
},
webview::{WebviewIpcHandler, WindowBuilder},
window::{dpi::PhysicalSize, DetachedWindow, FileDropEvent, PendingWindow, WindowEvent},
window::{dpi::PhysicalSize, DetachedWindow, FileDropEvent, PendingWindow},
},
utils::{
assets::Assets,
config::{AppUrl, Config, WindowUrl},
PackageInfo,
},
Context, EventLoopMessage, Icon, Invoke, Manager, Pattern, Runtime, Scopes, StateManager, Window,
WindowEvent,
};

#[cfg(any(target_os = "linux", target_os = "windows"))]
Expand Down Expand Up @@ -1147,7 +1148,7 @@ impl<R: Runtime> WindowManager<R> {
for handler in window_event_listeners.iter() {
handler(GlobalWindowEvent {
window: window_.clone(),
event: event.clone().into(),
event: event.clone(),
});
}
});
Expand Down Expand Up @@ -1274,9 +1275,9 @@ fn on_window_event<R: Runtime>(
match event {
WindowEvent::Resized(size) => window.emit(WINDOW_RESIZED_EVENT, size)?,
WindowEvent::Moved(position) => window.emit(WINDOW_MOVED_EVENT, position)?,
WindowEvent::CloseRequested { signal_tx } => {
WindowEvent::CloseRequested { api } => {
if window.has_js_listener(Some(window.label().into()), WINDOW_CLOSE_REQUESTED_EVENT) {
signal_tx.send(true).unwrap();
api.prevent_close();
}
window.emit(WINDOW_CLOSE_REQUESTED_EVENT, ())?;
}
Expand Down
9 changes: 6 additions & 3 deletions core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ use crate::{
webview::{WebviewAttributes, WindowBuilder as _},
window::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
DetachedWindow, JsEventListenerKey, PendingWindow, WindowEvent,
DetachedWindow, JsEventListenerKey, PendingWindow,
},
Dispatch, RuntimeHandle, UserAttentionType,
},
sealed::ManagerBase,
sealed::RuntimeOrDispatch,
utils::config::WindowUrl,
EventLoopMessage, Icon, Invoke, InvokeError, InvokeMessage, InvokeResolver, Manager,
PageLoadPayload, Runtime,
PageLoadPayload, Runtime, WindowEvent,
};

use serde::Serialize;
Expand Down Expand Up @@ -724,7 +724,10 @@ impl<R: Runtime> Window<R> {

/// Registers a window event listener.
pub fn on_window_event<F: Fn(&WindowEvent) + Send + 'static>(&self, f: F) {
self.window.dispatcher.on_window_event(f);
self
.window
.dispatcher
.on_window_event(move |event| f(&event.clone().into()));
}

/// Registers a menu event listener.
Expand Down

0 comments on commit 06aa87b

Please sign in to comment.