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 gpui::{
16 actions, point, AppContext, GlobalPixels, Pixels, PlatformDisplay, Size, Task, WindowBounds,
17 WindowKind, WindowOptions,
18};
19pub use panel_settings::{
20 ChatPanelSettings, CollaborationPanelSettings, NotificationPanelSettings,
21};
22use settings::Settings;
23use util::ResultExt;
24use workspace::AppState;
25
26actions!(ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall);
27
28pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
29 CollaborationPanelSettings::register(cx);
30 ChatPanelSettings::register(cx);
31 NotificationPanelSettings::register(cx);
32
33 // vcs_menu::init(cx);
34 collab_titlebar_item::init(cx);
35 collab_panel::init(cx);
36 // chat_panel::init(cx);
37 notifications::init(&app_state, 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 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 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 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, cx);
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 // todo!() use content bounds instead of screen.bounds and get rid of magics in point's 2nd argument.
111 let bounds = gpui::Bounds::<GlobalPixels> {
112 origin: screen_bounds.upper_right()
113 - point(
114 size.width + notification_margin_width,
115 notification_margin_height,
116 ),
117 size: window_size.into(),
118 };
119 WindowOptions {
120 bounds: WindowBounds::Fixed(bounds),
121 titlebar: None,
122 center: false,
123 focus: false,
124 show: true,
125 kind: WindowKind::PopUp,
126 is_movable: false,
127 display_id: Some(screen.id()),
128 }
129}
130
131// fn render_avatar<T: 'static>(
132// avatar: Option<Arc<ImageData>>,
133// avatar_style: &AvatarStyle,
134// container: ContainerStyle,
135// ) -> AnyElement<T> {
136// avatar
137// .map(|avatar| {
138// Image::from_data(avatar)
139// .with_style(avatar_style.image)
140// .aligned()
141// .contained()
142// .with_corner_radius(avatar_style.outer_corner_radius)
143// .constrained()
144// .with_width(avatar_style.outer_width)
145// .with_height(avatar_style.outer_width)
146// .into_any()
147// })
148// .unwrap_or_else(|| {
149// Empty::new()
150// .constrained()
151// .with_width(avatar_style.outer_width)
152// .into_any()
153// })
154// .contained()
155// .with_style(container)
156// .into_any()
157// }
158
159// fn is_channels_feature_enabled(cx: &gpui::WindowContext<'_>) -> bool {
160// cx.is_staff() || cx.has_flag::<ChannelsAlpha>()
161// }