diff --git a/crates/call2/src/call2.rs b/crates/call2/src/call2.rs index d983af50b7..534964b3c2 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 a58186d0f0..bfa2932aee 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 f906a19498..135a713661 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(); }