1use call::{report_call_event_for_room, ActiveCall};
2use gpui::{actions, AppContext, Task, WindowContext};
3use workspace::notifications::DetachAndPromptErr;
4
5actions!(
6 collab,
7 [ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall]
8);
9
10pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut WindowContext) {
11 let call = ActiveCall::global(cx).read(cx);
12 if let Some(room) = call.room().cloned() {
13 let client = call.client();
14 let toggle_screen_sharing = room.update(cx, |room, cx| {
15 if room.is_screen_sharing() {
16 report_call_event_for_room(
17 "disable screen share",
18 room.id(),
19 room.channel_id(),
20 &client,
21 );
22 Task::ready(room.unshare_screen(cx))
23 } else {
24 report_call_event_for_room(
25 "enable screen share",
26 room.id(),
27 room.channel_id(),
28 &client,
29 );
30 room.share_screen(cx)
31 }
32 });
33 toggle_screen_sharing.detach_and_prompt_err("Sharing Screen Failed", cx, |e, _| Some(format!("{:?}\n\nPlease check that you have given Zed permissions to record your screen in Settings.", e)));
34 }
35}
36
37pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
38 let call = ActiveCall::global(cx).read(cx);
39 if let Some(room) = call.room().cloned() {
40 let client = call.client();
41 room.update(cx, |room, cx| {
42 let operation = if room.is_muted() {
43 "enable microphone"
44 } else {
45 "disable microphone"
46 };
47 report_call_event_for_room(operation, room.id(), room.channel_id(), &client);
48
49 room.toggle_mute(cx)
50 });
51 }
52}
53
54pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
55 if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
56 room.update(cx, |room, cx| room.toggle_deafen(cx));
57 }
58}