fix(core): deadlock when creating new window with tracing feature (#11213)

This commit is contained in:
Lucas Fernandes Nogueira 2024-10-04 16:13:44 -03:00 committed by GitHub
parent 019f94f128
commit c72cd45ccd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 14 deletions

View File

@ -0,0 +1,5 @@
---
"tauri": patch:bug
---
Fixes a deadlock on window creation when the `tracing` feature is enabled.

View File

@ -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();
self.manager.emit_filter(
"tauri://window-created",
None,
Some(WindowCreatedEvent {
label: window.label().into(),
}),
|w| w != &window,
)?;
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(())
};
#[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)
}

View File

@ -4027,7 +4027,7 @@ checksum = "69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae"
[[package]]
name = "tauri"
version = "1.7.2"
version = "1.8.0"
dependencies = [
"anyhow",
"base64 0.22.1",
@ -4095,7 +4095,7 @@ dependencies = [
[[package]]
name = "tauri-build"
version = "1.5.4"
version = "1.5.5"
dependencies = [
"anyhow",
"cargo_toml",