Visual Studio Code, rebuilt in Rust
Rust
fix(dialog): hold the workbench weakly while a message box waits
rokarturd4d48c415146
diff --git a/native/crates/app/src/dialog.rs b/native/crates/app/src/dialog.rsindex 0733ca18546..61f7406293e 100644--- a/native/crates/app/src/dialog.rs+++ b/native/crates/app/src/dialog.rs@@ -83,13 +83,14 @@ pub fn show_message_box_with_checkbox(window: &Window, in_tests: InTests, level:let native_box = x_window.is_some();#[cfg(not(target_os = "linux"))]let native_box = true;- let workbench = crate::workbench::auxiliary_windows::window_workbench(window, cx);+ // Weak: the task waits on the custom dialog's answer, whose sender the workbench holds while the dialog is open.+ let workbench = crate::workbench::auxiliary_windows::window_workbench(window, cx).map(|workbench| workbench.downgrade());let (message, detail, checkbox) = (message.to_owned(), detail.map(str::to_owned), checkbox.map(|(label, checked)| (label.to_owned(), checked)));let buttons: Vec<String> = buttons.iter().map(|button| button.to_string()).collect();// Begun after this update returns: the sheet takes the key window and GPUI's handlers must not run re-entrantly,// and the workbench the caller updates can be read for its dialog style only then.cx.spawn(async move |cx| {- let style = workbench.as_ref().map(|workbench| workbench.read_with(cx, |workbench, _| (workbench.skip_dialogs, workbench.uses_custom_dialogs())));+ let style = workbench.as_ref().and_then(|workbench| workbench.read_with(cx, |workbench, _| (workbench.skip_dialogs, workbench.uses_custom_dialogs())).ok());let (skip_dialogs, custom) = style.unwrap_or_default();if skip_dialogs && in_tests != InTests::Show {if in_tests == InTests::Confirm {@@ -99,7 +100,7 @@ pub fn show_message_box_with_checkbox(window: &Window, in_tests: InTests, level:}// Without GTK on X11 (a Wayland session) the custom dialog stands in for Electron's GTK message box.if let (true, Some(workbench)) = (custom || !native_box, workbench) {- let answer = workbench.update(cx, |workbench, cx| workbench.show_custom_message_box(level, message, detail, buttons, checkbox, cx));+ let Ok(answer) = workbench.update(cx, |workbench, cx| workbench.show_custom_message_box(level, message, detail, buttons, checkbox, cx)) else { return };if let Ok(answer) = answer.await {let _ = sender.send(answer);}