1pub mod channel_view;
2pub mod chat_panel;
3pub mod collab_panel;
4mod collab_titlebar_item;
5mod face_pile;
6pub mod notification_panel;
7pub mod notifications;
8mod panel_settings;
9
10use std::{rc::Rc, sync::Arc};
11
12use call::{report_call_event_for_room, ActiveCall, Room};
13pub use collab_panel::CollabPanel;
14pub use collab_titlebar_item::CollabTitlebarItem;
15use feature_flags::{ChannelsAlpha, FeatureFlagAppExt};
16use gpui::{
17 actions, point, AppContext, GlobalPixels, Pixels, PlatformDisplay, Size, Task, WindowBounds,
18 WindowKind, WindowOptions,
19};
20pub use panel_settings::{
21 ChatPanelSettings, CollaborationPanelSettings, NotificationPanelSettings,
22};
23use settings::Settings;
24use util::ResultExt;
25use workspace::AppState;
26
27actions!(
28 collab,
29 [ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall]
30);
31
32pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
33 CollaborationPanelSettings::register(cx);
34 ChatPanelSettings::register(cx);
35 NotificationPanelSettings::register(cx);
36
37 vcs_menu::init(cx);
38 collab_titlebar_item::init(cx);
39 collab_panel::init(cx);
40 channel_view::init(cx);
41 chat_panel::init(cx);
42 notification_panel::init(cx);
43 notifications::init(&app_state, cx);
44}
45
46pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
47 let call = ActiveCall::global(cx).read(cx);
48 if let Some(room) = call.room().cloned() {
49 let client = call.client();
50 let toggle_screen_sharing = room.update(cx, |room, cx| {
51 if room.is_screen_sharing() {
52 report_call_event_for_room(
53 "disable screen share",
54 room.id(),
55 room.channel_id(),
56 &client,
57 );
58 Task::ready(room.unshare_screen(cx))
59 } else {
60 report_call_event_for_room(
61 "enable screen share",
62 room.id(),
63 room.channel_id(),
64 &client,
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 let operation = if room.is_muted(cx) {
79 "enable microphone"
80 } else {
81 "disable microphone"
82 };
83 report_call_event_for_room(operation, room.id(), room.channel_id(), &client);
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 PlatformDisplay>,
102 window_size: Size<Pixels>,
103) -> WindowOptions {
104 let notification_margin_width = GlobalPixels::from(16.);
105 let notification_margin_height = GlobalPixels::from(-0.) - GlobalPixels::from(48.);
106
107 let screen_bounds = screen.bounds();
108 let size: Size<GlobalPixels> = window_size.into();
109
110 let bounds = gpui::Bounds::<GlobalPixels> {
111 origin: screen_bounds.upper_right()
112 - point(
113 size.width + notification_margin_width,
114 notification_margin_height,
115 ),
116 size: window_size.into(),
117 };
118 WindowOptions {
119 bounds: WindowBounds::Fixed(bounds),
120 titlebar: None,
121 center: false,
122 focus: false,
123 show: true,
124 kind: WindowKind::PopUp,
125 is_movable: false,
126 display_id: Some(screen.id()),
127 }
128}
129
130fn is_channels_feature_enabled(cx: &gpui::WindowContext<'_>) -> bool {
131 cx.is_staff() || cx.has_flag::<ChannelsAlpha>()
132}