1pub mod collab_panel;
2mod collab_titlebar_item;
3mod contact_notification;
4mod face_pile;
5mod incoming_call_notification;
6mod notifications;
7mod project_shared_notification;
8mod sharing_status_indicator;
9
10use call::{ActiveCall, Room};
11pub use collab_titlebar_item::CollabTitlebarItem;
12use gpui::{
13 actions,
14 geometry::{
15 rect::RectF,
16 vector::{vec2f, Vector2F},
17 },
18 platform::{Screen, WindowBounds, WindowKind, WindowOptions},
19 AppContext, Task,
20};
21use std::{rc::Rc, sync::Arc};
22use util::ResultExt;
23use workspace::AppState;
24
25actions!(
26 collab,
27 [ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall]
28);
29
30pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
31 vcs_menu::init(cx);
32 collab_titlebar_item::init(cx);
33 collab_panel::init(app_state.client.clone(), cx);
34 incoming_call_notification::init(&app_state, cx);
35 project_shared_notification::init(&app_state, cx);
36 sharing_status_indicator::init(cx);
37
38 cx.add_global_action(toggle_screen_sharing);
39 cx.add_global_action(toggle_mute);
40 cx.add_global_action(toggle_deafen);
41}
42
43pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
44 let call = ActiveCall::global(cx).read(cx);
45 if let Some(room) = call.room().cloned() {
46 let client = call.client();
47 let toggle_screen_sharing = room.update(cx, |room, cx| {
48 if room.is_screen_sharing() {
49 ActiveCall::report_call_event_for_room(
50 "disable screen share",
51 room.id(),
52 room.channel_id(),
53 &client,
54 cx,
55 );
56 Task::ready(room.unshare_screen(cx))
57 } else {
58 ActiveCall::report_call_event_for_room(
59 "enable screen share",
60 room.id(),
61 room.channel_id(),
62 &client,
63 cx,
64 );
65 room.share_screen(cx)
66 }
67 });
68 toggle_screen_sharing.detach_and_log_err(cx);
69 }
70}
71
72pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
73 let call = ActiveCall::global(cx).read(cx);
74 if let Some(room) = call.room().cloned() {
75 let client = call.client();
76 room.update(cx, |room, cx| {
77 if room.is_muted(cx) {
78 ActiveCall::report_call_event_for_room(
79 "enable microphone",
80 room.id(),
81 room.channel_id(),
82 &client,
83 cx,
84 );
85 } else {
86 ActiveCall::report_call_event_for_room(
87 "disable microphone",
88 room.id(),
89 room.channel_id(),
90 &client,
91 cx,
92 );
93 }
94 room.toggle_mute(cx)
95 })
96 .map(|task| task.detach_and_log_err(cx))
97 .log_err();
98 }
99}
100
101pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
102 if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
103 room.update(cx, Room::toggle_deafen)
104 .map(|task| task.detach_and_log_err(cx))
105 .log_err();
106 }
107}
108
109fn notification_window_options(
110 screen: Rc<dyn Screen>,
111 window_size: Vector2F,
112) -> WindowOptions<'static> {
113 const NOTIFICATION_PADDING: f32 = 16.;
114
115 let screen_bounds = screen.content_bounds();
116 WindowOptions {
117 bounds: WindowBounds::Fixed(RectF::new(
118 screen_bounds.upper_right()
119 + vec2f(
120 -NOTIFICATION_PADDING - window_size.x(),
121 NOTIFICATION_PADDING,
122 ),
123 window_size,
124 )),
125 titlebar: None,
126 center: false,
127 focus: false,
128 show: true,
129 kind: WindowKind::PopUp,
130 is_movable: false,
131 screen: Some(screen),
132 }
133}