collab_ui.rs

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