Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 32b2133

Browse files
fix(core): deadlock on window create (tauri-apps#9429)
* fix(core): deadlock on window create * Update mod.rs Co-authored-by: Fabian-Lars <[email protected]> --------- Co-authored-by: Fabian-Lars <[email protected]>
1 parent 4973d73 commit 32b2133

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

core/tauri/src/window/mod.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,22 @@ tauri::Builder::default()
424424
crate::vibrancy::set_window_effects(&window, Some(effects))?;
425425
}
426426

427-
app_manager.webview.eval_script_all(format!(
428-
"window.__TAURI_INTERNALS__.metadata.windows = {window_labels_array}.map(function (label) {{ return {{ label: label }} }})",
429-
window_labels_array = serde_json::to_string(&app_manager.window.labels())?,
430-
))?;
431-
432-
app_manager.emit(
433-
"tauri://window-created",
434-
Some(crate::webview::CreatedEvent {
435-
label: window.label().into(),
436-
}),
437-
)?;
427+
let app_manager = self.manager.manager_owned();
428+
let window_label = window.label().to_string();
429+
// run on the main thread to fix a deadlock on webview.eval if the tracing feature is enabled
430+
let _ = window.run_on_main_thread(move || {
431+
let _ = app_manager.webview.eval_script_all(format!(
432+
"window.__TAURI_INTERNALS__.metadata.windows = {window_labels_array}.map(function (label) {{ return {{ label: label }} }})",
433+
window_labels_array = serde_json::to_string(&app_manager.window.labels()).unwrap(),
434+
));
435+
436+
let _ = app_manager.emit(
437+
"tauri://window-created",
438+
Some(crate::webview::CreatedEvent {
439+
label: window_label,
440+
}),
441+
);
442+
});
438443

439444
Ok(window)
440445
}

0 commit comments

Comments
 (0)