diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rs index 5463550587b8e0f15177009272c4f1c4f45bb72f..6152fae9d2349bbd571db0b52ce98de6f0109962 100644 --- a/crates/gpui2/src/app.rs +++ b/crates/gpui2/src/app.rs @@ -234,10 +234,10 @@ impl AppContext { app_version: platform.app_version().ok(), }; - Rc::new_cyclic(|this| AppCell { + let app = Rc::new_cyclic(|this| AppCell { app: RefCell::new(AppContext { this: this.clone(), - platform, + platform: platform.clone(), app_metadata, text_system, flushing_effects: false, @@ -269,12 +269,21 @@ impl AppContext { layout_id_buffer: Default::default(), propagate_event: true, }), - }) + }); + + platform.on_quit(Box::new({ + let cx = app.clone(); + move || { + cx.borrow_mut().shutdown(); + } + })); + + app } /// Quit the application gracefully. Handlers registered with `ModelContext::on_app_quit` /// will be given 100ms to complete before exiting. - pub fn quit(&mut self) { + pub fn shutdown(&mut self) { let mut futures = Vec::new(); for observer in self.quit_observers.remove(&()) { @@ -292,8 +301,10 @@ impl AppContext { { log::error!("timed out waiting on app_will_quit"); } + } - self.globals_by_type.clear(); + pub fn quit(&mut self) { + self.platform.quit(); } pub fn app_metadata(&self) -> AppMetadata { diff --git a/crates/gpui2/src/app/entity_map.rs b/crates/gpui2/src/app/entity_map.rs index 1ae9aec9b516175c008ff0952a1eba71e27f3652..1e01921cd458caf4ac3795c4d99ebc46a106b768 100644 --- a/crates/gpui2/src/app/entity_map.rs +++ b/crates/gpui2/src/app/entity_map.rs @@ -26,7 +26,7 @@ impl EntityId { impl Display for EntityId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self) + write!(f, "{}", self.as_u64()) } } diff --git a/crates/gpui2/src/app/test_context.rs b/crates/gpui2/src/app/test_context.rs index 44c31bbd69dad1325da8ec062551c3c03d67d7e2..51c564fdd88cb61b2351f952052643c42894b1c6 100644 --- a/crates/gpui2/src/app/test_context.rs +++ b/crates/gpui2/src/app/test_context.rs @@ -96,7 +96,7 @@ impl TestAppContext { } pub fn quit(&self) { - self.app.borrow_mut().quit(); + self.app.borrow_mut().shutdown(); } pub fn refresh(&mut self) -> Result<()> { diff --git a/crates/gpui2/src/platform/test/platform.rs b/crates/gpui2/src/platform/test/platform.rs index 4afcc4fc1ae436ef0b089809ac5e1b5b86207076..79a80a3d510256be18ffa991131de8e5b5c08a58 100644 --- a/crates/gpui2/src/platform/test/platform.rs +++ b/crates/gpui2/src/platform/test/platform.rs @@ -46,9 +46,7 @@ impl Platform for TestPlatform { unimplemented!() } - fn quit(&self) { - unimplemented!() - } + fn quit(&self) {} fn restart(&self) { unimplemented!() @@ -141,9 +139,7 @@ impl Platform for TestPlatform { unimplemented!() } - fn on_quit(&self, _callback: Box) { - unimplemented!() - } + fn on_quit(&self, _callback: Box) {} fn on_reopen(&self, _callback: Box) { unimplemented!() diff --git a/crates/live_kit_client2/examples/test_app.rs b/crates/live_kit_client2/examples/test_app.rs index 98302eb35c049015cbfee131b5dbcf125b7f5956..0b9e54f9b0dc7801f695adcf31b352d9997a48f1 100644 --- a/crates/live_kit_client2/examples/test_app.rs +++ b/crates/live_kit_client2/examples/test_app.rs @@ -167,7 +167,7 @@ fn main() { panic!("unexpected message"); } - cx.update(|cx| cx.quit()).ok(); + cx.update(|cx| cx.shutdown()).ok(); }) .detach(); }); diff --git a/crates/zed2/src/zed2.rs b/crates/zed2/src/zed2.rs index 73faeaaaf42a6aca435a61bb21c94c09a63e90f1..2f7a38b041ac8f26145c0257676f8816ef5e8c18 100644 --- a/crates/zed2/src/zed2.rs +++ b/crates/zed2/src/zed2.rs @@ -502,7 +502,6 @@ fn quit(_: &mut Workspace, _: &Quit, cx: &mut gpui::ViewContext) { cx.update(|_, cx| { cx.quit(); })?; - anyhow::Ok(()) }) .detach_and_log_err(cx);