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};
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 workspace::AppState;
25
26actions!(
27 collab,
28 [ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall]
29);
30
31pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
32 CollaborationPanelSettings::register(cx);
33 ChatPanelSettings::register(cx);
34 NotificationPanelSettings::register(cx);
35
36 vcs_menu::init(cx);
37 collab_titlebar_item::init(cx);
38 collab_panel::init(cx);
39 channel_view::init(cx);
40 chat_panel::init(cx);
41 notification_panel::init(cx);
42 notifications::init(&app_state, cx);
43}
44
45pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
46 let call = ActiveCall::global(cx).read(cx);
47 if let Some(room) = call.room().cloned() {
48 let client = call.client();
49 let toggle_screen_sharing = room.update(cx, |room, cx| {
50 if room.is_screen_sharing() {
51 report_call_event_for_room(
52 "disable screen share",
53 room.id(),
54 room.channel_id(),
55 &client,
56 );
57 Task::ready(room.unshare_screen(cx))
58 } else {
59 report_call_event_for_room(
60 "enable screen share",
61 room.id(),
62 room.channel_id(),
63 &client,
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 let operation = if room.is_muted() {
78 "enable microphone"
79 } else {
80 "disable microphone"
81 };
82 report_call_event_for_room(operation, room.id(), room.channel_id(), &client);
83
84 room.toggle_mute(cx)
85 });
86 }
87}
88
89pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
90 if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
91 room.update(cx, |room, cx| room.toggle_deafen(cx));
92 }
93}
94
95fn notification_window_options(
96 screen: Rc<dyn PlatformDisplay>,
97 window_size: Size<Pixels>,
98) -> WindowOptions {
99 let notification_margin_width = GlobalPixels::from(16.);
100 let notification_margin_height = GlobalPixels::from(-0.) - GlobalPixels::from(48.);
101
102 let screen_bounds = screen.bounds();
103 let size: Size<GlobalPixels> = window_size.into();
104
105 let bounds = gpui::Bounds::<GlobalPixels> {
106 origin: screen_bounds.upper_right()
107 - point(
108 size.width + notification_margin_width,
109 notification_margin_height,
110 ),
111 size: window_size.into(),
112 };
113 WindowOptions {
114 bounds: WindowBounds::Fixed(bounds),
115 titlebar: None,
116 center: false,
117 focus: false,
118 show: true,
119 kind: WindowKind::PopUp,
120 is_movable: false,
121 display_id: Some(screen.id()),
122 }
123}
124
125fn is_channels_feature_enabled(cx: &gpui::WindowContext<'_>) -> bool {
126 cx.is_staff() || cx.has_flag::<ChannelsAlpha>()
127}