Use AppContext instead of AsyncWindowContext to quit

Piotr Osiewicz created

Fixes refcell-related panic

Change summary

crates/call2/src/call2.rs                     | 6 +++---
crates/collab_ui2/src/collab_titlebar_item.rs | 9 ++++++++-
crates/workspace2/src/workspace2.rs           | 4 ++--
3 files changed, 13 insertions(+), 6 deletions(-)

Detailed changes

crates/call2/src/call2.rs 🔗

@@ -609,12 +609,12 @@ impl CallHandler for Call {
     fn room_id(&self, cx: &AppContext) -> Option<u64> {
         Some(self.active_call.as_ref()?.0.read(cx).room()?.read(cx).id())
     }
-    fn hang_up(&self, mut cx: AsyncWindowContext) -> Result<Task<Result<()>>> {
+    fn hang_up(&self, mut cx: &mut AppContext) -> Task<Result<()>> {
         let Some((call, _)) = self.active_call.as_ref() else {
-            bail!("Cannot exit a call; not in a call");
+            return Task::ready(Err(anyhow!("Cannot exit a call; not in a call")));
         };
 
-        call.update(&mut cx, |this, cx| this.hang_up(cx))
+        call.update(cx, |this, cx| this.hang_up(cx))
     }
     fn active_project(&self, cx: &AppContext) -> Option<WeakModel<Project>> {
         ActiveCall::global(cx).read(cx).location().cloned()

crates/collab_ui2/src/collab_titlebar_item.rs 🔗

@@ -230,7 +230,14 @@ impl Render for CollabTitlebarItem {
                         .child(
                             h_stack()
                                 .child(Button::new(if is_shared { "Unshare" } else { "Share" }))
-                                .child(IconButton::new("leave-call", ui::Icon::Exit)),
+                                .child(IconButton::new("leave-call", ui::Icon::Exit).on_click({
+                                    let workspace = workspace.clone();
+                                    move |_, cx| {
+                                        workspace.update(cx, |this, cx| {
+                                            this.call_state().hang_up(cx).detach();
+                                        });
+                                    }
+                                })),
                         )
                         .child(
                             h_stack()

crates/workspace2/src/workspace2.rs 🔗

@@ -479,7 +479,7 @@ pub trait CallHandler {
     fn is_in_room(&self, cx: &mut ViewContext<Workspace>) -> bool {
         self.room_id(cx).is_some()
     }
-    fn hang_up(&self, cx: AsyncWindowContext) -> Result<Task<Result<()>>>;
+    fn hang_up(&self, cx: &mut AppContext) -> Task<Result<()>>;
     fn active_project(&self, cx: &AppContext) -> Option<WeakModel<Project>>;
     fn invite(
         &mut self,
@@ -1222,7 +1222,7 @@ impl Workspace {
                 if answer.await.log_err() == Some(1) {
                     return anyhow::Ok(false);
                 } else {
-                    this.update(&mut cx, |this, cx| this.call_handler.hang_up(cx.to_async()))??
+                    this.update(&mut cx, |this, cx| this.call_handler.hang_up(cx))?
                         .await
                         .log_err();
                 }