Make `App::notify_view` private

Antonio Scandurra and Nathan Sobo created

Co-Authored-By: Nathan Sobo <nathan@zed.dev>

Change summary

crates/gpui/src/app.rs              |  6 +++---
crates/gpui/src/elements/tooltip.rs | 11 ++++++-----
2 files changed, 9 insertions(+), 8 deletions(-)

Detailed changes

crates/gpui/src/app.rs 🔗

@@ -1112,21 +1112,21 @@ impl AppContext {
         })
     }
 
-    pub(crate) fn notify_model(&mut self, model_id: usize) {
+    fn notify_model(&mut self, model_id: usize) {
         if self.pending_notifications.insert(model_id) {
             self.pending_effects
                 .push_back(Effect::ModelNotification { model_id });
         }
     }
 
-    pub(crate) fn notify_view(&mut self, window_id: usize, view_id: usize) {
+    fn notify_view(&mut self, window_id: usize, view_id: usize) {
         if self.pending_notifications.insert(view_id) {
             self.pending_effects
                 .push_back(Effect::ViewNotification { window_id, view_id });
         }
     }
 
-    pub(crate) fn notify_global(&mut self, type_id: TypeId) {
+    fn notify_global(&mut self, type_id: TypeId) {
         if self.pending_global_notifications.insert(type_id) {
             self.pending_effects
                 .push_back(Effect::GlobalNotification { type_id });

crates/gpui/src/elements/tooltip.rs 🔗

@@ -15,6 +15,7 @@ use std::{
     rc::Rc,
     time::Duration,
 };
+use util::ResultExt;
 
 const DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(500);
 
@@ -94,20 +95,20 @@ impl<V: View> Tooltip<V> {
         let child = MouseEventHandler::<MouseEventHandlerState<Tag>, _>::new(id, cx, |_, _| child)
             .on_hover(move |e, _, cx| {
                 let position = e.position;
-                let window_id = cx.window_id();
-                let view_id = cx.view_id();
                 if e.started {
                     if !state.visible.get() {
                         state.position.set(position);
 
                         let mut debounce = state.debounce.borrow_mut();
                         if debounce.is_none() {
-                            *debounce = Some(cx.spawn({
+                            *debounce = Some(cx.spawn_weak({
                                 let state = state.clone();
-                                |_, mut cx| async move {
+                                |view, mut cx| async move {
                                     cx.background().timer(DEBOUNCE_TIMEOUT).await;
                                     state.visible.set(true);
-                                    cx.update(|cx| cx.notify_view(window_id, view_id));
+                                    if let Some(view) = view.upgrade(&cx) {
+                                        view.update(&mut cx, |_, cx| cx.notify()).log_err();
+                                    }
                                 }
                             }));
                         }