Skip to content

Commit

Permalink
fix: dispatch focus event to app.run on Windows, closes #6460 (#6504)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Mar 31, 2023
1 parent 57c6bf0 commit ff4ea1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .changes/windows-focused-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri': 'patch'
'tauri-runtime-wry': 'patch'
---

On Windows, Fix missing `WindowEvent::Focused` in `App::run` callback.
34 changes: 19 additions & 15 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2532,21 +2532,7 @@ fn handle_user_message<T: UserEvent>(
let _ = webview.print();
}
}
WebviewMessage::WebviewEvent(event) => {
let window_event_listeners = windows
.borrow()
.get(&id)
.map(|w| w.window_event_listeners.clone());
if let Some(window_event_listeners) = window_event_listeners {
if let Some(event) = WindowEventWrapper::from(&event).0 {
let listeners = window_event_listeners.lock().unwrap();
let handlers = listeners.values();
for handler in handlers {
handler(&event);
}
}
}
}
WebviewMessage::WebviewEvent(_event) => { /* already handled */ }
},
Message::CreateWebview(window_id, handler) => match handler(event_loop, web_context) {
Ok(webview) => {
Expand Down Expand Up @@ -2840,6 +2826,24 @@ fn handle_event_loop<T: UserEvent>(
global_listener(id.0, &event);
}
}
Event::UserEvent(Message::Webview(id, WebviewMessage::WebviewEvent(event))) => {
if let Some(event) = WindowEventWrapper::from(&event).0 {
let windows = windows.borrow();
let window = windows.get(&id);
if let Some(window) = window {
callback(RunEvent::WindowEvent {
label: window.label.clone(),
event: event.clone(),
});

let listeners = window.window_event_listeners.lock().unwrap();
let handlers = listeners.values();
for handler in handlers {
handler(&event);
}
}
}
}
Event::WindowEvent {
event, window_id, ..
} => {
Expand Down

0 comments on commit ff4ea1e

Please sign in to comment.