From 6da5008f3250c930e29c0c401bf875d02d24b6c5 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Wed, 12 Jul 2023 16:09:39 -0400 Subject: [PATCH] Fix screen sharing panic introduced by call events Co-Authored-By: Max Brunsfeld --- crates/call/src/call.rs | 19 +++++++++++++------ crates/collab_ui/src/collab_ui.rs | 29 +++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/crates/call/src/call.rs b/crates/call/src/call.rs index ed5e560218..cf6dd1799c 100644 --- a/crates/call/src/call.rs +++ b/crates/call/src/call.rs @@ -263,7 +263,7 @@ impl ActiveCall { .borrow_mut() .take() .ok_or_else(|| anyhow!("no incoming call"))?; - self.report_call_event_for_room("decline incoming", call.room_id, cx); + Self::report_call_event_for_room("decline incoming", call.room_id, &self.client, cx); self.client.send(proto::DeclineCall { room_id: call.room_id, })?; @@ -373,22 +373,29 @@ impl ActiveCall { self.room.as_ref().map(|(room, _)| room) } + pub fn client(&self) -> Arc { + self.client.clone() + } + pub fn pending_invites(&self) -> &HashSet { &self.pending_invites } fn report_call_event(&self, operation: &'static str, cx: &AppContext) { if let Some(room) = self.room() { - self.report_call_event_for_room(operation, room.read(cx).id(), cx) + Self::report_call_event_for_room(operation, room.read(cx).id(), &self.client, cx) } } - fn report_call_event_for_room(&self, operation: &'static str, room_id: u64, cx: &AppContext) { - let telemetry = self.client.telemetry(); + pub fn report_call_event_for_room( + operation: &'static str, + room_id: u64, + client: &Arc, + cx: &AppContext, + ) { + let telemetry = client.telemetry(); let telemetry_settings = *settings::get::(cx); - let event = ClickhouseEvent::Call { operation, room_id }; - telemetry.report_clickhouse_event(event, telemetry_settings); } } diff --git a/crates/collab_ui/src/collab_ui.rs b/crates/collab_ui/src/collab_ui.rs index 3f5ca17a20..7608fdbfee 100644 --- a/crates/collab_ui/src/collab_ui.rs +++ b/crates/collab_ui/src/collab_ui.rs @@ -11,7 +11,7 @@ mod sharing_status_indicator; use call::{ActiveCall, Room}; pub use collab_titlebar_item::{CollabTitlebarItem, ToggleContactsMenu}; -use gpui::{actions, AppContext}; +use gpui::{actions, AppContext, Task}; use std::sync::Arc; use util::ResultExt; use workspace::AppState; @@ -44,9 +44,30 @@ pub fn init(app_state: &Arc, cx: &mut AppContext) { } pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) { - ActiveCall::global(cx).update(cx, |call, cx| { - call.toggle_screen_sharing(cx); - }); + let call = ActiveCall::global(cx).read(cx); + if let Some(room) = call.room().cloned() { + let client = call.client(); + let toggle_screen_sharing = room.update(cx, |room, cx| { + if room.is_screen_sharing() { + ActiveCall::report_call_event_for_room( + "disable screen share", + room.id(), + &client, + cx, + ); + Task::ready(room.unshare_screen(cx)) + } else { + ActiveCall::report_call_event_for_room( + "enable screen share", + room.id(), + &client, + cx, + ); + room.share_screen(cx) + } + }); + toggle_screen_sharing.detach_and_log_err(cx); + } } pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {