Add last window closed setting (#25185)

Release Notes:

- Added an `on_last_window_closed` setting, that allows users to quit
the app when the last window is closed

---------

Co-authored-by: Richard <richard@zed.dev>
This commit is contained in:
Mikayla Maki 2025-02-19 12:03:10 -08:00 committed by GitHub
parent ffc7558a1d
commit 40425093df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 171 additions and 8 deletions

View file

@ -104,6 +104,19 @@ pub fn init(cx: &mut App) {
}
}
fn bind_on_window_closed(cx: &mut App) -> Option<gpui::Subscription> {
WorkspaceSettings::get_global(cx)
.on_last_window_closed
.is_quit_app()
.then(|| {
cx.on_window_closed(|cx| {
if cx.windows().is_empty() {
cx.quit();
}
})
})
}
pub fn build_window_options(display_uuid: Option<Uuid>, cx: &mut App) -> WindowOptions {
let display = display_uuid.and_then(|uuid| {
cx.displays()
@ -144,6 +157,12 @@ pub fn initialize_workspace(
prompt_builder: Arc<PromptBuilder>,
cx: &mut App,
) {
let mut _on_close_subscription = bind_on_window_closed(cx);
cx.observe_global::<SettingsStore>(move |cx| {
_on_close_subscription = bind_on_window_closed(cx);
})
.detach();
cx.observe_new(move |workspace: &mut Workspace, window, cx| {
let Some(window) = window else {
return;