mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
fix(core): WindowEvent type used on Window::on_window_event (#3796)
This commit is contained in:
committed by
GitHub
parent
169b5035a9
commit
06aa87b65f
5
.changes/fix-on-window-event-type.md
Normal file
5
.changes/fix-on-window-event-type.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Fixes the `WindowEvent` type used on `Window::on_window_event`.
|
||||
@@ -40,7 +40,7 @@ use crate::{
|
||||
ResponseBuilder as HttpResponseBuilder,
|
||||
},
|
||||
webview::{WebviewIpcHandler, WindowBuilder},
|
||||
window::{dpi::PhysicalSize, DetachedWindow, FileDropEvent, PendingWindow, WindowEvent},
|
||||
window::{dpi::PhysicalSize, DetachedWindow, FileDropEvent, PendingWindow},
|
||||
},
|
||||
utils::{
|
||||
assets::Assets,
|
||||
@@ -48,6 +48,7 @@ use crate::{
|
||||
PackageInfo,
|
||||
},
|
||||
Context, EventLoopMessage, Icon, Invoke, Manager, Pattern, Runtime, Scopes, StateManager, Window,
|
||||
WindowEvent,
|
||||
};
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
@@ -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(),
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -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, ())?;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use crate::{
|
||||
webview::{WebviewAttributes, WindowBuilder as _},
|
||||
window::{
|
||||
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
|
||||
DetachedWindow, JsEventListenerKey, PendingWindow, WindowEvent,
|
||||
DetachedWindow, JsEventListenerKey, PendingWindow,
|
||||
},
|
||||
Dispatch, RuntimeHandle, UserAttentionType,
|
||||
},
|
||||
@@ -29,7 +29,7 @@ use crate::{
|
||||
sealed::RuntimeOrDispatch,
|
||||
utils::config::WindowUrl,
|
||||
EventLoopMessage, Icon, Invoke, InvokeError, InvokeMessage, InvokeResolver, Manager,
|
||||
PageLoadPayload, Runtime,
|
||||
PageLoadPayload, Runtime, WindowEvent,
|
||||
};
|
||||
|
||||
use serde::Serialize;
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user