BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / settings / calls.rs

calls.rs

calls.rs 3.2 KiB Download Raw
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::*;
3
4use super::rows::{Choice, caption, control_row, select, text_button, toggle_row};
5use crate::app_state::AppState;
6use crate::theme;
7use crate::notify::NotificationCenter;
8use crate::notify::sounds::{Ringtone, RingtoneCallType};
9
10const WEB_CALLS_LABEL: &str = "Use Teams on the web for calls and meetings";
11const WEB_CALLS_DETAIL: &str =
12 "Joins meetings and opens chat calls in a Teams on the web window instead of the built-in call engine.";
13
14pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &App) -> Div {
15 let web_calls = app.read(cx).web_calls;
16 let toggle_app = app.clone();
17 let ringtones = center.read(cx).settings().sounds.ringtones;
18 let rows = RingtoneCallType::ALL
19 .into_iter()
20 .filter(|call_type| {
21 *call_type == RingtoneCallType::Regular || ringtones.get(*call_type) != Ringtone::Ring
22 })
23 .map(|call_type| ringtone_row(center, call_type, ringtones.get(call_type)));
24 v_flex()
25 .w_full()
26 .child(caption("CALL ENGINE"))
27 .child(
28 toggle_row(
29 "settings-web-calls",
30 WEB_CALLS_LABEL,
31 WEB_CALLS_DETAIL,
32 theme::text_muted(),
33 web_calls,
34 )
35 .on_click(move |_, _, cx| {
36 toggle_app.update(cx, |state, cx| state.set_web_calls(!web_calls, cx))
37 }),
38 )
39 .child(caption("RINGTONES"))
40 .children(rows)
41}
42
43fn ringtone_row(
44 center: &Entity<NotificationCenter>,
45 call_type: RingtoneCallType,
46 current: Ringtone,
47) -> Div {
48 let choices = Ringtone::ALL
49 .iter()
50 .map(|ringtone| {
51 let (center, ringtone) = (center.clone(), *ringtone);
52 Choice::new(ringtone.label(), ringtone == current, move |cx| {
53 center.update(cx, |center, cx| {
54 center.update_settings(cx, |settings| {
55 settings.sounds.ringtones.set(call_type, ringtone)
56 });
57 center.preview_sound(ringtone.file_name(), cx);
58 })
59 })
60 })
61 .collect();
62 let (id, preview_id) = ringtone_ids(call_type);
63 let preview_center = center.clone();
64 control_row(
65 call_type.label(),
66 "",
67 h_flex()
68 .gap(px(8.))
69 .items_center()
70 .child(select(id, current.label(), false, choices))
71 .child(
72 text_button(preview_id, "Preview").on_click(move |_, _, cx| {
73 preview_center.update(cx, |center, cx| {
74 center.preview_sound(current.file_name(), cx)
75 })
76 }),
77 ),
78 )
79}
80
81fn ringtone_ids(call_type: RingtoneCallType) -> (&'static str, &'static str) {
82 match call_type {
83 RingtoneCallType::Regular => ("ringtone-regular", "ringtone-regular-preview"),
84 RingtoneCallType::CallGroup => ("ringtone-call-group", "ringtone-call-group-preview"),
85 RingtoneCallType::CallQueue => ("ringtone-call-queue", "ringtone-call-queue-preview"),
86 RingtoneCallType::Delegate => ("ringtone-delegate", "ringtone-delegate-preview"),
87 }
88}