Skip to content

Commit

Permalink
fix(core): update metadata before window-created listeners, closes #5191
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Oct 22, 2022
1 parent 161d5be commit e00b1e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-metadata-update.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Fixes access to the `WebviewWindow.getByLabel` function in a `tauri://window-created` event listener.
31 changes: 20 additions & 11 deletions core/tauri/src/event.rs
Expand Up @@ -327,17 +327,26 @@ pub fn listen_js(
handler: String,
) -> String {
format!(
"if (window['{listeners}'] === void 0) {{
Object.defineProperty(window, '{listeners}', {{ value: Object.create(null) }});
}}
if (window['{listeners}'][{event}] === void 0) {{
Object.defineProperty(window['{listeners}'], {event}, {{ value: [] }});
}}
window['{listeners}'][{event}].push({{
id: {event_id},
windowLabel: {window_label},
handler: {handler}
}});
"
(function () {{
if (window['{listeners}'] === void 0) {{
Object.defineProperty(window, '{listeners}', {{ value: Object.create(null) }});
}}
if (window['{listeners}'][{event}] === void 0) {{
Object.defineProperty(window['{listeners}'], {event}, {{ value: [] }});
}}
const eventListeners = window['{listeners}'][{event}]
const listener = {{
id: {event_id},
windowLabel: {window_label},
handler: {handler}
}};
if ({event} == 'tauri://window-created') {{
eventListeners.splice(eventListeners.length - 1, 0, listener)
}} else {{
eventListeners.push(listener);
}}
}})()
",
listeners = listeners_object_name,
event = event,
Expand Down

0 comments on commit e00b1e5

Please sign in to comment.