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    [ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall]
22);
23
24pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
25    vcs_menu::init(cx);
26    collab_titlebar_item::init(cx);
27    contact_list::init(cx);
28    contact_finder::init(cx);
29    contacts_popover::init(cx);
30    incoming_call_notification::init(&app_state, cx);
31    project_shared_notification::init(&app_state, cx);
32    sharing_status_indicator::init(cx);
33
34    cx.add_global_action(toggle_screen_sharing);
35    cx.add_global_action(toggle_mute);
36    cx.add_global_action(toggle_deafen);
37}
38
39pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
40    let call = ActiveCall::global(cx).read(cx);
41    if let Some(room) = call.room().cloned() {
42        let client = call.client();
43        let toggle_screen_sharing = room.update(cx, |room, cx| {
44            if room.is_screen_sharing() {
45                ActiveCall::report_call_event_for_room(
46                    "disable screen share",
47                    room.id(),
48                    &client,
49                    cx,
50                );
51                Task::ready(room.unshare_screen(cx))
52            } else {
53                ActiveCall::report_call_event_for_room(
54                    "enable screen share",
55                    room.id(),
56                    &client,
57                    cx,
58                );
59                room.share_screen(cx)
60            }
61        });
62        toggle_screen_sharing.detach_and_log_err(cx);
63    }
64}
65
66pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
67    let call = ActiveCall::global(cx).read(cx);
68    if let Some(room) = call.room().cloned() {
69        let client = call.client();
70        room.update(cx, |room, cx| {
71            if room.is_muted() {
72                ActiveCall::report_call_event_for_room("enable microphone", room.id(), &client, cx);
73            } else {
74                ActiveCall::report_call_event_for_room(
75                    "disable microphone",
76                    room.id(),
77                    &client,
78                    cx,
79                );
80            }
81            room.toggle_mute(cx)
82        })
83        .map(|task| task.detach_and_log_err(cx))
84        .log_err();
85    }
86}
87
88pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
89    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
90        room.update(cx, Room::toggle_deafen)
91            .map(|task| task.detach_and_log_err(cx))
92            .log_err();
93    }
94}