collab_ui.rs

  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    channel_view::init(cx);
 37    // chat_panel::init(cx);
 38    notifications::init(&app_state, cx);
 39
 40    // cx.add_global_action(toggle_screen_sharing);
 41    // cx.add_global_action(toggle_mute);
 42    // cx.add_global_action(toggle_deafen);
 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                    cx,
 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                    cx,
 66                );
 67                room.share_screen(cx)
 68            }
 69        });
 70        toggle_screen_sharing.detach_and_log_err(cx);
 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(cx) {
 80                "enable microphone"
 81            } else {
 82                "disable microphone"
 83            };
 84            report_call_event_for_room(operation, room.id(), room.channel_id(), &client, cx);
 85
 86            room.toggle_mute(cx)
 87        })
 88        .map(|task| task.detach_and_log_err(cx))
 89        .log_err();
 90    }
 91}
 92
 93pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
 94    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
 95        room.update(cx, Room::toggle_deafen)
 96            .map(|task| task.detach_and_log_err(cx))
 97            .log_err();
 98    }
 99}
100
101fn notification_window_options(
102    screen: Rc<dyn PlatformDisplay>,
103    window_size: Size<Pixels>,
104) -> WindowOptions {
105    let notification_margin_width = GlobalPixels::from(16.);
106    let notification_margin_height = GlobalPixels::from(-0.) - GlobalPixels::from(48.);
107
108    let screen_bounds = screen.bounds();
109    let size: Size<GlobalPixels> = window_size.into();
110
111    // todo!() use content bounds instead of screen.bounds and get rid of magics in point's 2nd argument.
112    let bounds = gpui::Bounds::<GlobalPixels> {
113        origin: screen_bounds.upper_right()
114            - point(
115                size.width + notification_margin_width,
116                notification_margin_height,
117            ),
118        size: window_size.into(),
119    };
120    WindowOptions {
121        bounds: WindowBounds::Fixed(bounds),
122        titlebar: None,
123        center: false,
124        focus: false,
125        show: true,
126        kind: WindowKind::PopUp,
127        is_movable: false,
128        display_id: Some(screen.id()),
129    }
130}
131
132// fn render_avatar<T: 'static>(
133//     avatar: Option<Arc<ImageData>>,
134//     avatar_style: &AvatarStyle,
135//     container: ContainerStyle,
136// ) -> AnyElement<T> {
137//     avatar
138//         .map(|avatar| {
139//             Image::from_data(avatar)
140//                 .with_style(avatar_style.image)
141//                 .aligned()
142//                 .contained()
143//                 .with_corner_radius(avatar_style.outer_corner_radius)
144//                 .constrained()
145//                 .with_width(avatar_style.outer_width)
146//                 .with_height(avatar_style.outer_width)
147//                 .into_any()
148//         })
149//         .unwrap_or_else(|| {
150//             Empty::new()
151//                 .constrained()
152//                 .with_width(avatar_style.outer_width)
153//                 .into_any()
154//         })
155//         .contained()
156//         .with_style(container)
157//         .into_any()
158// }
159
160// fn is_channels_feature_enabled(cx: &gpui::WindowContext<'_>) -> bool {
161//     cx.is_staff() || cx.has_flag::<ChannelsAlpha>()
162// }