Skip to content

Commit

Permalink
fix(core): deadlock when creating new window with tracing feature (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Oct 4, 2024
1 parent 019f94f commit c72cd45
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-deadlock-tracing-window-creation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:bug
---

Fixes a deadlock on window creation when the `tracing` feature is enabled.
40 changes: 28 additions & 12 deletions core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,19 +351,35 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
}
.map(|window| self.manager.attach_window(self.app_handle.clone(), window))?;

self.manager.eval_script_all(format!(
"window.__TAURI_METADATA__.__windows = {window_labels_array}.map(function (label) {{ return {{ label: label }} }})",
window_labels_array = serde_json::to_string(&self.manager.labels())?,
))?;
let manager = self.manager.clone();
let label = window.label().to_string();

let window_created_hook = move || {
manager.eval_script_all(format!(
"window.__TAURI_METADATA__.__windows = {window_labels_array}.map(function (label) {{ return {{ label: label }} }})",
window_labels_array = serde_json::to_string(&manager.labels())?,
))?;

manager.emit_filter(
"tauri://window-created",
None,
Some(WindowCreatedEvent {
label: label.clone(),
}),
|w| w.label() != label,
)?;

crate::Result::Ok(())
};

self.manager.emit_filter(
"tauri://window-created",
None,
Some(WindowCreatedEvent {
label: window.label().into(),
}),
|w| w != &window,
)?;
#[cfg(not(feature = "tracing"))]
window_created_hook()?;
#[cfg(feature = "tracing")]
std::thread::spawn(move || {
if let Err(e) = window_created_hook() {
log::error!("failed to trigger window creation hooks: {e}");
}
});

Ok(window)
}
Expand Down
4 changes: 2 additions & 2 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 c72cd45

Please sign in to comment.