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