From a860a6cd62ae5a91b1311330d7bc719496f71730 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 21 Apr 2023 16:50:57 +0200 Subject: [PATCH] Make `App::notify_view` private Co-Authored-By: Nathan Sobo --- crates/gpui/src/app.rs | 6 +++--- crates/gpui/src/elements/tooltip.rs | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 9ef2cf4020770147199b82bcc2fdc9bd7585aaf8..762837c478a8b5eb363d62e6b866e94cfba31483 100644 --- a/crates/gpui/src/app.rs +++ b/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 }); diff --git a/crates/gpui/src/elements/tooltip.rs b/crates/gpui/src/elements/tooltip.rs index 6d2d8d2cc4c091a75c1d389085942ebc608f1738..d30c0994008ef870cf84b4a7c456699b402be118 100644 --- a/crates/gpui/src/elements/tooltip.rs +++ b/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 Tooltip { let child = MouseEventHandler::, _>::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(); + } } })); }