diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 5def0fcf5073a0424674143ec8ce930e31fab848..3c04ea16966f597dee8fd7b00ab2e18f94edbd21 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -3120,6 +3120,19 @@ impl<'a, T: Entity> ModelContext<'a, T> { }) } + pub fn observe_global(&mut self, mut callback: F) -> Subscription + where + G: Any, + F: 'static + FnMut(&mut T, &mut ModelContext), + { + let observer = self.weak_handle(); + self.app.observe_global::(move |cx| { + if let Some(observer) = observer.upgrade(cx) { + observer.update(cx, |observer, cx| callback(observer, cx)); + } + }) + } + pub fn observe_release( &mut self, handle: &ModelHandle,