Disallow multiple quit confirmations (#24180)

Closes https://github.com/zed-industries/zed/issues/10192 , again.

Release Notes:

- Fixed multiple save modals appearing when app is being closed multiple
times
This commit is contained in:
Kirill Bulatov 2025-02-04 11:09:46 +02:00 committed by GitHub
parent 386cfacb25
commit 6659aea13b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -44,6 +44,7 @@ use settings::{
}; };
use std::any::TypeId; use std::any::TypeId;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::atomic::{self, AtomicBool};
use std::time::Duration; use std::time::Duration;
use std::{borrow::Cow, ops::Deref, path::Path, sync::Arc}; use std::{borrow::Cow, ops::Deref, path::Path, sync::Arc};
use terminal_view::terminal_panel::{self, TerminalPanel}; 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); .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) { fn quit(_: &Quit, cx: &mut App) {
if WAITING_QUIT_CONFIRMATION.load(atomic::Ordering::Acquire) {
return;
}
let should_confirm = WorkspaceSettings::get_global(cx).confirm_quit; let should_confirm = WorkspaceSettings::get_global(cx).confirm_quit;
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
let mut workspace_windows = cx.update(|cx| { let mut workspace_windows = cx.update(|cx| {
@ -954,23 +960,27 @@ fn quit(_: &Quit, cx: &mut App) {
}) })
.log_err(); .log_err();
if let (true, Some(workspace)) = (should_confirm, workspace_windows.first().copied()) { if should_confirm {
let answer = workspace if let Some(workspace) = workspace_windows.first() {
.update(&mut cx, |_, window, cx| { let answer = workspace
window.prompt( .update(&mut cx, |_, window, cx| {
PromptLevel::Info, window.prompt(
"Are you sure you want to quit?", PromptLevel::Info,
None, "Are you sure you want to quit?",
&["Quit", "Cancel"], None,
cx, &["Quit", "Cancel"],
) cx,
}) )
.log_err(); })
.log_err();
if let Some(answer) = answer { if let Some(answer) = answer {
let answer = answer.await.ok(); WAITING_QUIT_CONFIRMATION.store(true, atomic::Ordering::Release);
if answer != Some(0) { let answer = answer.await.ok();
return Ok(()); WAITING_QUIT_CONFIRMATION.store(false, atomic::Ordering::Release);
if answer != Some(0) {
return Ok(());
}
} }
} }
} }