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 gpui::{
16 actions, point, AppContext, DevicePixels, Pixels, PlatformDisplay, Size, Task,
17 WindowBackgroundAppearance, WindowBounds, WindowContext, WindowKind, WindowOptions,
18};
19use panel_settings::MessageEditorSettings;
20pub use panel_settings::{
21 ChatPanelSettings, CollaborationPanelSettings, NotificationPanelSettings,
22};
23use release_channel::ReleaseChannel;
24use settings::Settings;
25use workspace::{notifications::DetachAndPromptErr, 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 MessageEditorSettings::register(cx);
37
38 vcs_menu::init(cx);
39 collab_titlebar_item::init(cx);
40 collab_panel::init(cx);
41 channel_view::init(cx);
42 chat_panel::init(cx);
43 notification_panel::init(cx);
44 notifications::init(&app_state, cx);
45}
46
47pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut WindowContext) {
48 let call = ActiveCall::global(cx).read(cx);
49 if let Some(room) = call.room().cloned() {
50 let client = call.client();
51 let toggle_screen_sharing = room.update(cx, |room, cx| {
52 if room.is_screen_sharing() {
53 report_call_event_for_room(
54 "disable screen share",
55 room.id(),
56 room.channel_id(),
57 &client,
58 );
59 Task::ready(room.unshare_screen(cx))
60 } else {
61 report_call_event_for_room(
62 "enable screen share",
63 room.id(),
64 room.channel_id(),
65 &client,
66 );
67 room.share_screen(cx)
68 }
69 });
70 toggle_screen_sharing.detach_and_prompt_err("Sharing Screen Failed", cx, |e, _| Some(format!("{:?}\n\nPlease check that you have given Zed permissions to record your screen in Settings.", e)));
71 }
72}
73
74pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
75 let call = ActiveCall::global(cx).read(cx);
76 if let Some(room) = call.room().cloned() {
77 let client = call.client();
78 room.update(cx, |room, cx| {
79 let operation = if room.is_muted() {
80 "enable microphone"
81 } else {
82 "disable microphone"
83 };
84 report_call_event_for_room(operation, room.id(), room.channel_id(), &client);
85
86 room.toggle_mute(cx)
87 });
88 }
89}
90
91pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
92 if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
93 room.update(cx, |room, cx| room.toggle_deafen(cx));
94 }
95}
96
97fn notification_window_options(
98 screen: Rc<dyn PlatformDisplay>,
99 window_size: Size<Pixels>,
100 cx: &AppContext,
101) -> WindowOptions {
102 let notification_margin_width = DevicePixels::from(16);
103 let notification_margin_height = DevicePixels::from(-0) - DevicePixels::from(48);
104
105 let screen_bounds = screen.bounds();
106 let size: Size<DevicePixels> = window_size.into();
107
108 let bounds = gpui::Bounds::<DevicePixels> {
109 origin: screen_bounds.upper_right()
110 - point(
111 size.width + notification_margin_width,
112 notification_margin_height,
113 ),
114 size: window_size.into(),
115 };
116
117 let app_id = ReleaseChannel::global(cx).app_id();
118
119 WindowOptions {
120 window_bounds: Some(WindowBounds::Windowed(bounds)),
121 titlebar: None,
122 focus: false,
123 show: true,
124 kind: WindowKind::PopUp,
125 is_movable: false,
126 display_id: Some(screen.id()),
127 window_background: WindowBackgroundAppearance::default(),
128 app_id: Some(app_id.to_owned()),
129 }
130}