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