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