zed/crates/collab_ui/src/collab_ui.rs

143 lines
4.1 KiB
Rust
Raw Normal View History

pub mod channel_view;
pub mod chat_panel;
pub mod collab_panel;
mod collab_titlebar_item;
mod contact_notification;
mod face_pile;
2022-09-29 13:33:33 +00:00
mod incoming_call_notification;
mod notifications;
2023-09-08 20:28:19 +00:00
mod panel_settings;
mod project_shared_notification;
mod sharing_status_indicator;
2023-06-20 16:32:16 +00:00
use call::{ActiveCall, Room};
use gpui::{
actions,
geometry::{
rect::RectF,
vector::{vec2f, Vector2F},
},
platform::{Screen, WindowBounds, WindowKind, WindowOptions},
AppContext, Task,
};
use std::{rc::Rc, sync::Arc};
2023-06-20 19:36:36 +00:00
use util::ResultExt;
2023-04-28 09:12:09 +00:00
use workspace::AppState;
2023-09-08 20:28:19 +00:00
pub use collab_titlebar_item::CollabTitlebarItem;
pub use panel_settings::{ChatPanelSettings, CollaborationPanelSettings};
2023-06-22 11:49:36 +00:00
actions!(
collab,
[ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall]
2023-06-22 11:49:36 +00:00
);
2023-04-28 09:12:09 +00:00
pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
2023-09-08 20:28:19 +00:00
settings::register::<CollaborationPanelSettings>(cx);
settings::register::<ChatPanelSettings>(cx);
vcs_menu::init(cx);
2022-10-06 14:10:45 +00:00
collab_titlebar_item::init(cx);
collab_panel::init(cx);
chat_panel::init(cx);
2023-04-28 09:12:09 +00:00
incoming_call_notification::init(&app_state, cx);
project_shared_notification::init(&app_state, cx);
sharing_status_indicator::init(cx);
cx.add_global_action(toggle_screen_sharing);
2023-06-16 18:16:36 +00:00
cx.add_global_action(toggle_mute);
cx.add_global_action(toggle_deafen);
}
pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
let call = ActiveCall::global(cx).read(cx);
if let Some(room) = call.room().cloned() {
let client = call.client();
let toggle_screen_sharing = room.update(cx, |room, cx| {
if room.is_screen_sharing() {
ActiveCall::report_call_event_for_room(
"disable screen share",
Some(room.id()),
room.channel_id(),
&client,
cx,
);
Task::ready(room.unshare_screen(cx))
} else {
ActiveCall::report_call_event_for_room(
"enable screen share",
Some(room.id()),
room.channel_id(),
&client,
cx,
);
room.share_screen(cx)
}
});
toggle_screen_sharing.detach_and_log_err(cx);
}
}
2023-06-16 18:16:36 +00:00
pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
2023-07-20 20:00:11 +00:00
let call = ActiveCall::global(cx).read(cx);
2023-07-20 20:21:21 +00:00
if let Some(room) = call.room().cloned() {
2023-07-20 20:00:11 +00:00
let client = call.client();
room.update(cx, |room, cx| {
if room.is_muted(cx) {
ActiveCall::report_call_event_for_room(
"enable microphone",
Some(room.id()),
room.channel_id(),
&client,
cx,
);
2023-07-20 20:00:11 +00:00
} else {
ActiveCall::report_call_event_for_room(
"disable microphone",
Some(room.id()),
room.channel_id(),
2023-07-20 20:00:11 +00:00
&client,
cx,
);
}
room.toggle_mute(cx)
})
.map(|task| task.detach_and_log_err(cx))
.log_err();
2023-06-16 18:16:36 +00:00
}
}
pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
2023-06-20 19:36:36 +00:00
room.update(cx, Room::toggle_deafen)
.map(|task| task.detach_and_log_err(cx))
.log_err();
2023-06-16 18:16:36 +00:00
}
}
fn notification_window_options(
screen: Rc<dyn Screen>,
window_size: Vector2F,
) -> WindowOptions<'static> {
const NOTIFICATION_PADDING: f32 = 16.;
let screen_bounds = screen.content_bounds();
WindowOptions {
bounds: WindowBounds::Fixed(RectF::new(
screen_bounds.upper_right()
+ vec2f(
-NOTIFICATION_PADDING - window_size.x(),
NOTIFICATION_PADDING,
),
window_size,
)),
titlebar: None,
center: false,
focus: false,
show: true,
kind: WindowKind::PopUp,
is_movable: false,
screen: Some(screen),
}
}