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        ShareMicrophone
26    ]
27);
28
29pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
30    collab_titlebar_item::init(cx);
31    contact_list::init(cx);
32    contact_finder::init(cx);
33    contacts_popover::init(cx);
34    incoming_call_notification::init(&app_state, cx);
35    project_shared_notification::init(&app_state, cx);
36    sharing_status_indicator::init(cx);
37
38    cx.add_global_action(toggle_screen_sharing);
39    cx.add_global_action(toggle_mute);
40    cx.add_global_action(toggle_deafen);
41    cx.add_global_action(share_microphone);
42}
43
44pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
45    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
46        let toggle_screen_sharing = room.update(cx, |room, cx| {
47            if room.is_screen_sharing() {
48                Task::ready(room.unshare_screen(cx))
49            } else {
50                room.share_screen(cx)
51            }
52        });
53        toggle_screen_sharing.detach_and_log_err(cx);
54    }
55}
56
57pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
58    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
59        room.update(cx, Room::toggle_mute)
60            .map(|task| task.detach_and_log_err(cx))
61            .log_err();
62    }
63}
64
65pub fn toggle_deafen(_: &ToggleDeafen, cx: &mut AppContext) {
66    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
67        room.update(cx, Room::toggle_deafen)
68            .map(|task| task.detach_and_log_err(cx))
69            .log_err();
70    }
71}
72
73pub fn share_microphone(_: &ShareMicrophone, cx: &mut AppContext) {
74    if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
75        room.update(cx, Room::share_microphone)
76            .detach_and_log_err(cx)
77    }
78}