Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Disallow multiple quit confirmations (#24180)
Kirill Bulatov6659aea13be4
diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rsindex c8196b45273..220623dfe24 100644--- a/crates/zed/src/zed.rs+++ b/crates/zed/src/zed.rs@@ -44,6 +44,7 @@ use settings::{};use std::any::TypeId;use std::path::PathBuf;+use std::sync::atomic::{self, AtomicBool};use std::time::Duration;use std::{borrow::Cow, ops::Deref, path::Path, sync::Arc};use terminal_view::terminal_panel::{self, TerminalPanel};@@ -937,7 +938,12 @@ fn install_cli(.detach_and_prompt_err("Error installing zed cli", window, cx, |_, _, _| None);}+static WAITING_QUIT_CONFIRMATION: AtomicBool = AtomicBool::new(false);fn quit(_: &Quit, cx: &mut App) {+ if WAITING_QUIT_CONFIRMATION.load(atomic::Ordering::Acquire) {+ return;+ }+let should_confirm = WorkspaceSettings::get_global(cx).confirm_quit;cx.spawn(|mut cx| async move {let mut workspace_windows = cx.update(|cx| {@@ -954,23 +960,27 @@ fn quit(_: &Quit, cx: &mut App) {}).log_err();- if let (true, Some(workspace)) = (should_confirm, workspace_windows.first().copied()) {- let answer = workspace- .update(&mut cx, |_, window, cx| {- window.prompt(- PromptLevel::Info,- "Are you sure you want to quit?",- None,- &["Quit", "Cancel"],- cx,- )- })- .log_err();+ if should_confirm {+ if let Some(workspace) = workspace_windows.first() {+ let answer = workspace+ .update(&mut cx, |_, window, cx| {+ window.prompt(+ PromptLevel::Info,+ "Are you sure you want to quit?",+ None,+ &["Quit", "Cancel"],+ cx,+ )+ })+ .log_err();- if let Some(answer) = answer {- let answer = answer.await.ok();- if answer != Some(0) {- return Ok(());+ if let Some(answer) = answer {+ WAITING_QUIT_CONFIRMATION.store(true, atomic::Ordering::Release);+ let answer = answer.await.ok();+ WAITING_QUIT_CONFIRMATION.store(false, atomic::Ordering::Release);+ if answer != Some(0) {+ return Ok(());+ }}}}