collab_ui.rs

 1mod collab_titlebar_item;
 2mod contact_finder;
 3mod contact_list;
 4mod contact_notification;
 5mod contacts_popover;
 6mod face_pile;
 7mod incoming_call_notification;
 8mod notifications;
 9mod project_shared_notification;
10mod sharing_status_indicator;
11
12use call::{ActiveCall, Room};
13pub use collab_titlebar_item::{CollabTitlebarItem, ToggleContactsMenu};
14use gpui::{actions, AppContext, Task};
15use std::sync::Arc;
16use util::ResultExt;
17use workspace::AppState;
18
19actions!(
20    collab,
21    [
22        ToggleScreenSharing,
23        ToggleMute,
24        ToggleDeafen,
25        LeaveCall,
26        ShareMicrophone
27    ]
28);
29
30pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
31    vcs_menu::init(cx);
32    collab_titlebar_item::init(cx);
33    contact_list::init(cx);
34    contact_finder::init(cx);
35    contacts_popover::init(cx);
36    incoming_call_notification::init(&app_state, cx);
37    project_shared_notification::init(&app_state, cx);
38    sharing_status_indicator::init(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    cx.add_global_action(share_microphone);
44}
45
46pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
47    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
48        let toggle_screen_sharing = room.update(cx, |room, cx| {
49            if room.is_screen_sharing() {
50                Task::ready(room.unshare_screen(cx))
51            } else {
52                room.share_screen(cx)
53            }
54        });
55        toggle_screen_sharing.detach_and_log_err(cx);
56    }
57}
58
59pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
60    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
61        room.update(cx, Room::toggle_mute)
62            .map(|task| task.detach_and_log_err(cx))
63            .log_err();
64    }
65}
66
67pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
68    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
69        room.update(cx, Room::toggle_deafen)
70            .map(|task| task.detach_and_log_err(cx))
71            .log_err();
72    }
73}
74
75pub fn share_microphone(_: &ShareMicrophone, cx: &mut AppContext) {
76    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
77        room.update(cx, Room::share_microphone)
78            .detach_and_log_err(cx)
79    }
80}