Skip to content

Commit

Permalink
fix(core): global events regression from #7996 closes #8146 (#8147)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Nov 7, 2023
1 parent 04a682b commit b5f40ae
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-global-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:bug
---

Fixes global events not reaching to window listeners.
5 changes: 1 addition & 4 deletions core/tauri/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ pub fn event_initialization_script(function: &str, listeners: &str) -> String {
for (let i = listeners.length - 1; i >= 0; i--) {{
const listener = listeners[i]
if (
(listener.windowLabel && listener.windowLabel === eventData.windowLabel) ||
(!listener.windowLabel && (listener.windowLabel === null || eventData.windowLabel === null))
) {{
if (listener.windowLabel === null || eventData.windowLabel === null || listener.windowLabel === eventData.windowLabel) {{
eventData.id = listener.id
listener.handler(eventData)
}}
Expand Down
22 changes: 15 additions & 7 deletions core/tauri/src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2405,14 +2405,22 @@ impl<R: Runtime> Window<R> {

/// Whether this window registered a listener to an event from the given window and event name.
pub(crate) fn has_js_listener(&self, window_label: Option<String>, event: &str) -> bool {
self
.js_event_listeners
.lock()
.unwrap()
.contains_key(&JsEventListenerKey {
window_label,
event: event.into(),
let listeners = self.js_event_listeners.lock().unwrap();

if let Some(label) = window_label {
let event = event.to_string();
// window-specific event is also triggered on global events, so we check that
listeners.contains_key(&JsEventListenerKey {
window_label: Some(label),
event: event.clone(),
}) || listeners.contains_key(&JsEventListenerKey {
window_label: None,
event,
})
} else {
// for global events, any listener is triggered
listeners.keys().any(|k| k.event == event)
}
}

/// Opens the developer tools window (Web Inspector).
Expand Down
14 changes: 7 additions & 7 deletions examples/api/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b5f40ae

Please sign in to comment.