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 &client,
53 cx,
54 );
55 Task::ready(room.unshare_screen(cx))
56 } else {
57 ActiveCall::report_call_event_for_room(
58 "enable screen share",
59 room.id(),
60 &client,
61 cx,
62 );
63 room.share_screen(cx)
64 }
65 });
66 toggle_screen_sharing.detach_and_log_err(cx);
67 }
68}
69
70pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
71 let call = ActiveCall::global(cx).read(cx);
72 if let Some(room) = call.room().cloned() {
73 let client = call.client();
74 room.update(cx, |room, cx| {
75 if room.is_muted(cx) {
76 ActiveCall::report_call_event_for_room("enable microphone", room.id(), &client, cx);
77 } else {
78 ActiveCall::report_call_event_for_room(
79 "disable microphone",
80 room.id(),
81 &client,
82 cx,
83 );
84 }
85 room.toggle_mute(cx)
86 })
87 .map(|task| task.detach_and_log_err(cx))
88 .log_err();
89 }
90}
91
92pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
93 if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
94 room.update(cx, Room::toggle_deafen)
95 .map(|task| task.detach_and_log_err(cx))
96 .log_err();
97 }
98}
99
100fn notification_window_options(
101 screen: Rc<dyn Screen>,
102 window_size: Vector2F,
103) -> WindowOptions<'static> {
104 const NOTIFICATION_PADDING: f32 = 16.;
105
106 let screen_bounds = screen.content_bounds();
107 WindowOptions {
108 bounds: WindowBounds::Fixed(RectF::new(
109 screen_bounds.upper_right()
110 + vec2f(
111 -NOTIFICATION_PADDING - window_size.x(),
112 NOTIFICATION_PADDING,
113 ),
114 window_size,
115 )),
116 titlebar: None,
117 center: false,
118 focus: false,
119 show: true,
120 kind: WindowKind::PopUp,
121 is_movable: false,
122 screen: Some(screen),
123 }
124}