diff --git a/crates/call2/src/call2.rs b/crates/call2/src/call2.rs index d983af50b76bf754aac95cfa90f530968de92ece..534964b3c27b9fc214b8909752a4757b3c745e36 100644 --- a/crates/call2/src/call2.rs +++ b/crates/call2/src/call2.rs @@ -609,12 +609,12 @@ impl CallHandler for Call { fn room_id(&self, cx: &AppContext) -> Option { Some(self.active_call.as_ref()?.0.read(cx).room()?.read(cx).id()) } - fn hang_up(&self, mut cx: AsyncWindowContext) -> Result>> { + fn hang_up(&self, mut cx: &mut AppContext) -> Task> { 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> { ActiveCall::global(cx).read(cx).location().cloned() diff --git a/crates/collab_ui2/src/collab_titlebar_item.rs b/crates/collab_ui2/src/collab_titlebar_item.rs index a58186d0f0d6064395a7fb762ee6e385266f1f02..bfa2932aee237ba5fdb95df13400981e31092f0e 100644 --- a/crates/collab_ui2/src/collab_titlebar_item.rs +++ b/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() diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index f906a194983f48f05d922c941ea74c77aaf99103..135a713661725017ee99f4ff93170ade724d70eb 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -479,7 +479,7 @@ pub trait CallHandler { fn is_in_room(&self, cx: &mut ViewContext) -> bool { self.room_id(cx).is_some() } - fn hang_up(&self, cx: AsyncWindowContext) -> Result>>; + fn hang_up(&self, cx: &mut AppContext) -> Task>; fn active_project(&self, cx: &AppContext) -> Option>; 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(); }