BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / notify / settings_view.rs

settings_view.rs

settings_view.rs 34.3 KiB Download Raw
1use std::time::{Duration, Instant};
2
3use calling::camera::{DEFAULT_CAMERA_LABEL, list_cameras};
4use calling::{CameraEffects, DeviceChoice, DeviceEntry, MicSettings, NoiseSuppression, camera_entries};
5use gpui_kit::assets::IconName;
6use gpui_kit::component::{
7 button::Button,
8 h_flex,
9 menu::{DropdownMenu as _, PopupMenuItem},
10 v_flex,
11};
12use gpui_kit::base::Disableable as _;
13use gpui_kit::prelude::FluentBuilder as _;
14use gpui_kit::*;
15
16use super::center::NotificationCenter;
17use super::sounds::{AlertSound, Ringtone, RingtoneCallType};
18use super::rules::Settings;
19use super::settings_mcp::McpView;
20use crate::agents::AgentsSettings;
21use crate::app_state::AppState;
22use crate::call::{BackgroundPick, CameraPreview, preview_backgrounds};
23use crate::theme;
24
25const FPS_TICK: Duration = Duration::from_millis(500);
26const SELECT_WIDTH: f32 = 170.;
27const SOUND_SELECT_WIDTH: f32 = 124.;
28const PREVIEW_WIDTH: f32 = 380.;
29const PREVIEW_HEIGHT: f32 = 214.;
30const PREVIEW_RADIUS: f32 = 10.;
31const SOFT_FOCUS_LEVELS: [(&str, u8); 3] = [("Low", 25), ("Medium", 50), ("High", 75)];
32const CAMERA_IN_USE: &str = "Camera is in use by the call";
33
34fn camera_in_call(state: &AppState) -> bool {
35 state.call.is_some()
36}
37
38#[derive(Clone, Copy, PartialEq, Eq)]
39pub(super) enum Section {
40 Notifications,
41 Calls,
42 Devices,
43 Agents,
44 Mcp,
45}
46
47impl Section {
48 const ALL: [Section; 5] = [
49 Section::Notifications,
50 Section::Calls,
51 Section::Devices,
52 Section::Agents,
53 Section::Mcp,
54 ];
55
56 fn label(self) -> &'static str {
57 match self {
58 Section::Notifications => "Notifications",
59 Section::Calls => "Calls",
60 Section::Devices => "Devices",
61 Section::Agents => "Agents",
62 Section::Mcp => "MCP",
63 }
64 }
65}
66
67type Accessor = fn(&mut Settings) -> &mut bool;
68
69struct Row {
70 title: &'static str,
71 detail: &'static str,
72 field: Accessor,
73}
74
75const ROWS: [Row; 5] = [
76 Row {
77 title: "Mentions only",
78 detail: "Direct messages and @mentions",
79 field: |settings| &mut settings.mentions_only,
80 },
81 Row {
82 title: "Show preview",
83 detail: "Off: only \"New message\"",
84 field: |settings| &mut settings.preview,
85 },
86 Row {
87 title: "Flash taskbar",
88 detail: "On new messages, until you open the window",
89 field: |settings| &mut settings.flash,
90 },
91 Row {
92 title: "Mute notifications during calls and meetings",
93 detail: "No message toasts while a call is active",
94 field: |settings| &mut settings.mute_in_calls,
95 },
96 Row {
97 title: "Minimize to tray on close",
98 detail: "The title bar X hides the window",
99 field: |settings| &mut settings.close_to_tray,
100 },
101];
102
103const NOTIFICATION_SOUND_ROW: Row = Row {
104 title: "Play sounds with notifications",
105 detail: "",
106 field: |settings| &mut settings.sounds.notification_sound,
107};
108
109const URGENT_SOUND_ROW: Row = Row {
110 title: "Play sounds with urgent and priority contact notifications",
111 detail: "",
112 field: |settings| &mut settings.sounds.urgent_sound,
113};
114
115const CALL_SOUND_ROWS: [Row; 2] = [
116 Row {
117 title: "Play sounds with incoming calls, requests to join, and meeting start notifications",
118 detail: "",
119 field: |settings| &mut settings.sounds.call_and_meeting_sound,
120 },
121 Row {
122 title: "Play sounds when I'm busy or in a meeting",
123 detail: "",
124 field: |settings| &mut settings.sounds.sound_when_busy,
125 },
126];
127
128type SoundAccessor = fn(&mut Settings) -> &mut AlertSound;
129
130pub struct SettingsView {
131 center: Entity<NotificationCenter>,
132 section: Section,
133 mcp: Entity<McpView>,
134 agents: Option<Entity<AgentsSettings>>,
135 preview: CameraPreview,
136 cameras: Vec<DeviceEntry>,
137 cameras_requested: bool,
138 camera: DeviceChoice,
139 background: BackgroundPick,
140 preview_blocked: bool,
141 _subscription: Subscription,
142 _app_subscription: Subscription,
143 _release: Subscription,
144}
145
146impl SettingsView {
147 pub const WIDTH: f32 = 420.;
148 pub const HEIGHT: f32 = 680.;
149
150 pub fn new(
151 center: Entity<NotificationCenter>,
152 section: Section,
153 window: &mut Window,
154 cx: &mut Context<Self>,
155 ) -> Self {
156 let subscription = cx.observe(&center, |_, _, cx| cx.notify());
157 let app = center.read(cx).app().clone();
158 let app_subscription = cx.observe(&app, |view, _, cx| view.sync_preview_block(cx));
159 let release = cx.on_release(|view, cx| view.preview.stop(cx));
160 let (preview, mut updates) = CameraPreview::new();
161 let mcp = cx.new(|cx| McpView::new(app.clone(), window, cx));
162 let state = app.read(cx);
163 let camera = state.call_camera.clone();
164 preview.set_effects(state.call_effects);
165 let preview_blocked = camera_in_call(state);
166 let background = Some(state.call_background.clone())
167 .filter(|pick| {
168 preview_backgrounds(&state.call_backgrounds)
169 .iter()
170 .any(|(known, _)| known == pick)
171 })
172 .unwrap_or_default();
173 cx.spawn(async move |this, cx| {
174 while updates.recv().await.is_some() {
175 if this.update(cx, |view, cx| view.take_frames(cx)).is_err() {
176 return;
177 }
178 }
179 })
180 .detach();
181 cx.spawn(async move |this, cx| {
182 loop {
183 cx.background_executor().timer(FPS_TICK).await;
184 if this.update(cx, |view, cx| view.tick(cx)).is_err() {
185 break;
186 }
187 }
188 })
189 .detach();
190 let agents =
191 crate::agents::runs_handle(cx).map(|runs| cx.new(|cx| AgentsSettings::new(runs, cx)));
192 SettingsView {
193 center,
194 section,
195 mcp,
196 agents,
197 preview,
198 cameras: camera_entries(&[]),
199 cameras_requested: false,
200 camera,
201 background,
202 preview_blocked,
203 _subscription: subscription,
204 _app_subscription: app_subscription,
205 _release: release,
206 }
207 }
208
209 fn take_frames(&mut self, cx: &mut Context<Self>) {
210 self.preview.take_frames(cx);
211 cx.notify();
212 }
213
214 fn tick(&mut self, cx: &mut Context<Self>) {
215 if self.section == Section::Devices {
216 self.preview.tick(Instant::now());
217 cx.notify();
218 }
219 }
220
221 pub(super) fn select_section(&mut self, section: Section, cx: &mut Context<Self>) {
222 if self.section == section {
223 return;
224 }
225 self.section = section;
226 match section {
227 Section::Devices => {
228 self.load_cameras(cx);
229 self.apply_background(cx);
230 self.preview
231 .set_effects(self.center.read(cx).app().read(cx).call_effects);
232 self.preview_blocked = camera_in_call(self.center.read(cx).app().read(cx));
233 self.start_preview();
234 }
235 Section::Notifications | Section::Calls | Section::Agents | Section::Mcp => {
236 self.preview.stop(cx)
237 }
238 }
239 cx.notify();
240 }
241
242 fn load_cameras(&mut self, cx: &mut Context<Self>) {
243 if std::mem::replace(&mut self.cameras_requested, true) {
244 return;
245 }
246 cx.spawn(async move |this, cx| {
247 let cameras = cx
248 .background_executor()
249 .spawn(async { list_cameras() })
250 .await;
251 this.update(cx, |view, cx| {
252 view.cameras = camera_entries(&cameras);
253 cx.notify();
254 })
255 .ok();
256 })
257 .detach();
258 }
259
260 fn start_preview(&mut self) {
261 if !self.preview_blocked {
262 self.preview.start(&self.camera);
263 }
264 }
265
266 fn sync_preview_block(&mut self, cx: &mut Context<Self>) {
267 let blocked = camera_in_call(self.center.read(cx).app().read(cx));
268 if blocked == self.preview_blocked {
269 return;
270 }
271 self.preview_blocked = blocked;
272 if blocked {
273 self.preview.stop(cx);
274 } else if self.section == Section::Devices {
275 self.start_preview();
276 }
277 cx.notify();
278 }
279
280 fn select_camera(&mut self, camera: DeviceChoice, cx: &mut Context<Self>) {
281 self.camera = camera.clone();
282 let app = self.center.read(cx).app().clone();
283 app.update(cx, |state, cx| state.select_call_camera(camera, cx));
284 self.start_preview();
285 cx.notify();
286 }
287
288 fn set_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) {
289 let app = self.center.read(cx).app().clone();
290 app.update(cx, |state, cx| state.set_call_mic(settings, cx));
291 cx.notify();
292 }
293
294 fn set_report_enabled(&mut self, on: bool, cx: &mut Context<Self>) {
295 let app = self.center.read(cx).app().clone();
296 app.update(cx, |state, cx| state.set_call_report_enabled(on, cx));
297 cx.notify();
298 }
299
300 fn change_effects(&mut self, change: fn(&mut CameraEffects), cx: &mut Context<Self>) {
301 let app = self.center.read(cx).app().clone();
302 let mut effects = app.read(cx).call_effects;
303 change(&mut effects);
304 self.preview.set_effects(effects);
305 app.update(cx, |state, cx| state.set_call_effects(effects, cx));
306 cx.notify();
307 }
308
309 fn effect_row(
310 &self,
311 id: &'static str,
312 title: &'static str,
313 on: bool,
314 change: fn(&mut CameraEffects),
315 cx: &mut Context<Self>,
316 ) -> Stateful<Div> {
317 let view = cx.entity();
318 h_flex()
319 .id(id)
320 .w_full()
321 .px(px(20.))
322 .py(px(6.))
323 .gap(px(12.))
324 .items_center()
325 .cursor_pointer()
326 .hover(|row| row.bg(theme::row_hover()))
327 .on_click(move |_, _, cx| view.update(cx, |view, cx| view.change_effects(change, cx)))
328 .child(
329 div()
330 .flex_1()
331 .text_size(px(14.))
332 .font_weight(FontWeight::SEMIBOLD)
333 .text_color(theme::text())
334 .child(title),
335 )
336 .child(switch(on))
337 }
338
339 fn strength_row(&self, strength: u8, cx: &mut Context<Self>) -> Stateful<Div> {
340 let levels = SOFT_FOCUS_LEVELS.map(|(label, level)| {
341 let view = cx.entity();
342 let app = self.center.read(cx).app().clone();
343 button(label)
344 .when(strength == level, |button| {
345 button.bg(theme::accent()).text_color(theme::on_accent())
346 })
347 .on_click(move |_, _, cx| {
348 app.update(cx, |state, cx| {
349 let effects = CameraEffects {
350 soft_focus_strength: level,
351 ..state.call_effects
352 };
353 state.set_call_effects(effects, cx);
354 view.update(cx, |view, cx| {
355 view.preview.set_effects(effects);
356 cx.notify();
357 });
358 })
359 })
360 });
361 h_flex()
362 .id("effect-soft-focus-strength")
363 .w_full()
364 .px(px(20.))
365 .py(px(6.))
366 .gap(px(8.))
367 .items_center()
368 .child(
369 div()
370 .flex_1()
371 .text_size(px(12.))
372 .text_color(theme::text_muted())
373 .child("Soft focus strength"),
374 )
375 .children(levels)
376 }
377
378 fn select_background(&mut self, pick: BackgroundPick, cx: &mut Context<Self>) {
379 self.background = pick.clone();
380 let app = self.center.read(cx).app().clone();
381 app.update(cx, |state, cx| state.set_call_background(pick, cx));
382 self.apply_background(cx);
383 cx.notify();
384 }
385
386 fn apply_background(&self, cx: &App) {
387 let state = self.center.read(cx).app().read(cx);
388 if let Some(choice) = state.call_backgrounds.choice_for(&self.background) {
389 self.preview.set_background(choice);
390 }
391 }
392}
393
394pub(crate) fn switch(on: bool) -> Div {
395 div()
396 .w(px(36.))
397 .h(px(20.))
398 .flex_none()
399 .rounded_full()
400 .relative()
401 .bg(if on {
402 theme::accent()
403 } else {
404 theme::border_strong()
405 })
406 .child(
407 div()
408 .absolute()
409 .top(px(2.))
410 .left(px(if on { 18. } else { 2. }))
411 .size(px(16.))
412 .rounded_full()
413 .bg(theme::text()),
414 )
415}
416
417fn button(label: &'static str) -> Stateful<Div> {
418 button_with_id(label, label)
419}
420
421fn button_with_id(id: &'static str, label: &'static str) -> Stateful<Div> {
422 div()
423 .id(id)
424 .h(px(32.))
425 .px(px(14.))
426 .flex()
427 .items_center()
428 .rounded(px(8.))
429 .border_1()
430 .border_color(theme::border_strong())
431 .cursor_pointer()
432 .text_size(px(13.))
433 .font_weight(FontWeight::SEMIBOLD)
434 .text_color(theme::text())
435 .hover(|button| button.bg(theme::row_hover()))
436 .child(label)
437}
438
439fn titled(title: &'static str, detail: impl Into<SharedString>) -> Div {
440 titled_with(title, detail, theme::text_muted())
441}
442
443pub(super) fn titled_with(
444 title: &'static str,
445 detail: impl Into<SharedString>,
446 detail_color: Hsla,
447) -> Div {
448 v_flex()
449 .flex_1()
450 .min_w(px(0.))
451 .child(
452 div()
453 .text_size(px(14.))
454 .font_weight(FontWeight::SEMIBOLD)
455 .text_color(theme::text())
456 .child(title),
457 )
458 .map(|column| {
459 let detail = detail.into();
460 if detail.is_empty() {
461 return column;
462 }
463 column.child(
464 div()
465 .text_size(px(12.))
466 .text_color(detail_color)
467 .child(detail),
468 )
469 })
470}
471
472pub(super) fn control_row(
473 title: &'static str,
474 detail: impl Into<SharedString>,
475 control: impl IntoElement,
476) -> Div {
477 h_flex()
478 .w_full()
479 .px(px(20.))
480 .py(px(10.))
481 .gap(px(12.))
482 .items_center()
483 .child(titled(title, detail))
484 .child(control)
485}
486
487fn section_tab(section: Section, active: bool, view: Entity<SettingsView>) -> Stateful<Div> {
488 div()
489 .id(section.label())
490 .h(px(32.))
491 .px(px(14.))
492 .flex()
493 .items_center()
494 .rounded(px(8.))
495 .cursor_pointer()
496 .text_size(px(13.))
497 .font_weight(FontWeight::SEMIBOLD)
498 .text_color(if active {
499 theme::on_accent()
500 } else {
501 theme::text()
502 })
503 .when(active, |tab| tab.bg(theme::accent()))
504 .when(!active, |tab| tab.hover(|tab| tab.bg(theme::row_hover())))
505 .child(section.label())
506 .on_click(move |_, _, cx| view.update(cx, |view, cx| view.select_section(section, cx)))
507}
508
509fn heading(title: &'static str) -> Div {
510 div()
511 .w_full()
512 .px(px(20.))
513 .pt(px(16.))
514 .pb(px(4.))
515 .text_size(px(12.))
516 .font_weight(FontWeight::SEMIBOLD)
517 .text_color(theme::text_muted())
518 .child(title)
519}
520
521fn picker(
522 id: &'static str,
523 label: &'static str,
524 disabled: bool,
525 menu_items: impl Fn() -> Vec<(&'static str, bool, Box<dyn Fn(&mut App)>)> + 'static,
526) -> impl IntoElement {
527 Button::new(id)
528 .outline()
529 .w(px(SOUND_SELECT_WIDTH))
530 .label(label)
531 .icon(IconName::ChevronDown)
532 .disabled(disabled)
533 .dropdown_menu(move |menu, _, _| {
534 menu_items()
535 .into_iter()
536 .fold(menu, |menu, (label, checked, choose)| {
537 menu.item(
538 PopupMenuItem::new(label)
539 .checked(checked)
540 .on_click(move |_, _, cx| choose(cx)),
541 )
542 })
543 })
544}
545
546impl SettingsView {
547 fn switch_row(&self, row: &Row, on: bool) -> Stateful<Div> {
548 let center = self.center.clone();
549 let field = row.field;
550 h_flex()
551 .id(row.title)
552 .w_full()
553 .px(px(20.))
554 .py(px(10.))
555 .gap(px(12.))
556 .items_center()
557 .cursor_pointer()
558 .hover(|row| row.bg(theme::row_hover()))
559 .on_click(move |_, _, cx| {
560 center.update(cx, |center, cx| {
561 center.update_settings(cx, |settings| {
562 let value = field(settings);
563 *value = !*value;
564 })
565 });
566 })
567 .child(titled(row.title, row.detail))
568 .child(switch(on))
569 }
570
571 fn alert_sound_row(
572 &self,
573 (id, preview_id): (&'static str, &'static str),
574 title: &'static str,
575 options: &'static [AlertSound],
576 current: AlertSound,
577 enabled: bool,
578 field: SoundAccessor,
579 ) -> Div {
580 let center = self.center.clone();
581 let preview_center = self.center.clone();
582 let choices = move || {
583 options
584 .iter()
585 .map(|sound| {
586 let (center, sound) = (center.clone(), *sound);
587 let choose: Box<dyn Fn(&mut App)> = Box::new(move |cx| {
588 center.update(cx, |center, cx| {
589 center.update_settings(cx, |settings| *field(settings) = sound);
590 center.preview_sound(sound.file_name(), cx);
591 })
592 });
593 (sound.label(), sound == current, choose)
594 })
595 .collect()
596 };
597 control_row(
598 title,
599 "",
600 h_flex()
601 .gap(px(8.))
602 .items_center()
603 .child(picker(id, current.label(), !enabled, choices))
604 .child(button_with_id(preview_id, "Preview").on_click(
605 move |_, _, cx| {
606 preview_center
607 .update(cx, |center, cx| center.preview_sound(current.file_name(), cx))
608 },
609 )),
610 )
611 }
612
613 fn ringtone_row(&self, call_type: RingtoneCallType, current: Ringtone) -> Div {
614 let center = self.center.clone();
615 let preview_center = self.center.clone();
616 let choices = move || {
617 Ringtone::ALL
618 .iter()
619 .map(|ringtone| {
620 let (center, ringtone) = (center.clone(), *ringtone);
621 let choose: Box<dyn Fn(&mut App)> = Box::new(move |cx| {
622 center.update(cx, |center, cx| {
623 center.update_settings(cx, |settings| {
624 settings.sounds.ringtones.set(call_type, ringtone)
625 });
626 center.preview_sound(ringtone.file_name(), cx);
627 })
628 });
629 (ringtone.label(), ringtone == current, choose)
630 })
631 .collect()
632 };
633 let (id, preview_id) = ringtone_ids(call_type);
634 control_row(
635 call_type.label(),
636 "",
637 h_flex()
638 .gap(px(8.))
639 .items_center()
640 .child(picker(id, current.label(), false, choices))
641 .child(button_with_id(preview_id, "Preview").on_click(
642 move |_, _, cx| {
643 preview_center.update(cx, |center, cx| {
644 center.preview_sound(current.file_name(), cx)
645 })
646 },
647 )),
648 )
649 }
650
651 fn calls_section(&self, cx: &App) -> Div {
652 let ringtones = self.center.read(cx).settings().sounds.ringtones;
653 let rows = RingtoneCallType::ALL
654 .into_iter()
655 .filter(|call_type| {
656 *call_type == RingtoneCallType::Regular
657 || ringtones.get(*call_type) != Ringtone::Ring
658 })
659 .map(|call_type| self.ringtone_row(call_type, ringtones.get(call_type)));
660 v_flex()
661 .w_full()
662 .pt(px(8.))
663 .child(heading("Choose a ringtone"))
664 .children(rows)
665 }
666
667 fn devices_section(&self, cx: &mut Context<Self>) -> Div {
668 let view = cx.entity();
669 let camera_label = self
670 .cameras
671 .iter()
672 .find(|entry| entry.choice == self.camera)
673 .map_or(DEFAULT_CAMERA_LABEL.to_owned(), |entry| entry.label.clone());
674 let cameras = self.cameras.clone();
675 let current_camera = self.camera.clone();
676 let camera_view = view.clone();
677 let backgrounds =
678 preview_backgrounds(&self.center.read(cx).app().read(cx).call_backgrounds);
679 let background_label = backgrounds
680 .iter()
681 .find(|(pick, _)| *pick == self.background)
682 .map_or("None".to_owned(), |(_, label)| label.clone());
683 let current_background = self.background.clone();
684 let mic = self.center.read(cx).app().read(cx).call_mic;
685 let noise_view = view.clone();
686 let music_view = view.clone();
687 let report_view = view.clone();
688 let report_on = self.center.read(cx).app().read(cx).call_report_enabled;
689 let effects = self.center.read(cx).app().read(cx).call_effects;
690 let image = self.preview.image(Instant::now());
691 let status = if self.preview_blocked {
692 CAMERA_IN_USE.to_owned()
693 } else {
694 self.preview.failure().map_or_else(
695 || {
696 self.preview
697 .fps()
698 .map_or("Starting camera...".to_owned(), |fps| {
699 format!("{fps:.0} fps")
700 })
701 },
702 |reason| format!("Camera could not start: {reason}"),
703 )
704 };
705 v_flex()
706 .w_full()
707 .child(control_row(
708 "Camera",
709 "Preview stays on this computer",
710 Button::new("camera-select")
711 .outline()
712 .w(px(SELECT_WIDTH))
713 .label(camera_label)
714 .icon(IconName::ChevronDown)
715 .dropdown_menu(move |menu, _, _| {
716 cameras.iter().fold(menu, |menu, entry| {
717 let (view, choice) = (camera_view.clone(), entry.choice.clone());
718 menu.item(
719 PopupMenuItem::new(entry.label.clone())
720 .checked(entry.choice == current_camera)
721 .on_click(move |_, _, cx| {
722 view.update(cx, |view, cx| {
723 view.select_camera(choice.clone(), cx)
724 })
725 }),
726 )
727 })
728 }),
729 ))
730 .child(control_row(
731 "Background",
732 "Blur or a picture behind you",
733 Button::new("background-select")
734 .outline()
735 .w(px(SELECT_WIDTH))
736 .label(background_label)
737 .icon(IconName::ChevronDown)
738 .dropdown_menu(move |menu, _, _| {
739 backgrounds.iter().fold(menu, |menu, (pick, label)| {
740 let (view, pick) = (view.clone(), pick.clone());
741 menu.item(
742 PopupMenuItem::new(label.clone())
743 .checked(pick == current_background)
744 .on_click(move |_, _, cx| {
745 view.update(cx, |view, cx| {
746 view.select_background(pick.clone(), cx)
747 })
748 }),
749 )
750 })
751 }),
752 ))
753 .child(control_row(
754 "Noise suppression",
755 if mic.music_mode {
756 "Off while music mode is on"
757 } else {
758 "Echo, hum and background noise"
759 },
760 Button::new("noise-suppression-select")
761 .outline()
762 .w(px(SELECT_WIDTH))
763 .label(mic.noise_suppression.label())
764 .icon(IconName::ChevronDown)
765 .disabled(mic.music_mode)
766 .dropdown_menu(move |menu, _, _| {
767 NoiseSuppression::ALL.iter().fold(menu, |menu, level| {
768 let (view, level) = (noise_view.clone(), *level);
769 menu.item(
770 PopupMenuItem::new(level.label())
771 .checked(level == mic.noise_suppression)
772 .on_click(move |_, _, cx| {
773 view.update(cx, |view, cx| {
774 view.set_mic(
775 MicSettings {
776 noise_suppression: level,
777 ..mic
778 },
779 cx,
780 )
781 })
782 }),
783 )
784 })
785 }),
786 ))
787 .child(
788 control_row(
789 "Music mode",
790 "Keeps echo cancellation, turns off the rest",
791 switch(mic.music_mode),
792 )
793 .id("music-mode-row")
794 .cursor_pointer()
795 .hover(|row| row.bg(theme::row_hover()))
796 .on_click(move |_, _, cx| {
797 music_view.update(cx, |view, cx| {
798 view.set_mic(
799 MicSettings {
800 music_mode: !mic.music_mode,
801 ..mic
802 },
803 cx,
804 )
805 })
806 }),
807 )
808 .child(
809 control_row(
810 "Save a test report after each call",
811 "Pseudonymized, stays on this computer",
812 switch(report_on),
813 )
814 .id("call-report-row")
815 .cursor_pointer()
816 .hover(|row| row.bg(theme::row_hover()))
817 .on_click(move |_, _, cx| {
818 report_view.update(cx, |view, cx| view.set_report_enabled(!report_on, cx))
819 }),
820 )
821 .child(
822 v_flex()
823 .w_full()
824 .px(px(20.))
825 .pt(px(8.))
826 .gap(px(8.))
827 .child(
828 div()
829 .w(px(PREVIEW_WIDTH))
830 .h(px(PREVIEW_HEIGHT))
831 .flex()
832 .items_center()
833 .justify_center()
834 .overflow_hidden()
835 .rounded(px(PREVIEW_RADIUS))
836 .bg(theme::surface())
837 .children(image.map(|image| {
838 img(ImageSource::Render(image))
839 .size_full()
840 .object_fit(ObjectFit::Cover)
841 .rounded(px(PREVIEW_RADIUS))
842 })),
843 )
844 .child(
845 div()
846 .text_size(px(12.))
847 .text_color(theme::text_muted())
848 .child(status),
849 ),
850 )
851 .child(
852 v_flex()
853 .id("camera-effects")
854 .w_full()
855 .pt(px(8.))
856 .child(self.effect_row(
857 "effect-mirror",
858 "Mirror my video",
859 effects.mirror,
860 |effects| effects.mirror = !effects.mirror,
861 cx,
862 ))
863 .child(self.effect_row(
864 "effect-framing",
865 "Auto framing",
866 effects.auto_framing,
867 |effects| effects.auto_framing = !effects.auto_framing,
868 cx,
869 ))
870 .child(self.effect_row(
871 "effect-brightness",
872 "Adjust brightness",
873 effects.adjust_brightness,
874 |effects| effects.adjust_brightness = !effects.adjust_brightness,
875 cx,
876 ))
877 .child(self.effect_row(
878 "effect-soft-focus",
879 "Soft focus",
880 effects.soft_focus,
881 |effects| effects.soft_focus = !effects.soft_focus,
882 cx,
883 ))
884 .when(effects.soft_focus, |column| {
885 column.child(self.strength_row(effects.soft_focus_strength, cx))
886 }),
887 )
888 }
889}
890
891impl Render for SettingsView {
892 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
893 let view = cx.entity();
894 let tabs = h_flex().w_full().px(px(20.)).gap(px(8.)).children(
895 Section::ALL.map(|section| section_tab(section, section == self.section, view.clone())),
896 );
897 let body = match self.section {
898 Section::Notifications => div()
899 .id("notifications-scroll")
900 .flex_1()
901 .min_h(px(0.))
902 .overflow_y_scroll()
903 .child(self.notifications_section(cx))
904 .into_any_element(),
905 Section::Calls => self.calls_section(cx).into_any_element(),
906 Section::Devices => div()
907 .id("devices-scroll")
908 .flex_1()
909 .min_h(px(0.))
910 .overflow_y_scroll()
911 .child(self.devices_section(cx))
912 .into_any_element(),
913 Section::Agents => div()
914 .id("agents-scroll")
915 .flex_1()
916 .min_h(px(0.))
917 .overflow_y_scroll()
918 .children(self.agents.clone())
919 .into_any_element(),
920 Section::Mcp => self.mcp.clone().into_any_element(),
921 };
922 v_flex()
923 .size_full()
924 .bg(theme::background())
925 .pt(px(12.))
926 .child(tabs)
927 .child(body)
928 }
929}
930
931impl SettingsView {
932 fn notifications_section(&self, cx: &App) -> Div {
933 let mut current = self.center.read(cx).settings().clone();
934 let corner = current.corner;
935 let sounds = current.sounds.clone();
936 let rows: Vec<Stateful<Div>> = ROWS
937 .iter()
938 .map(|row| {
939 let on = *(row.field)(&mut current);
940 self.switch_row(row, on)
941 })
942 .collect();
943 let call_sound_rows: Vec<Stateful<Div>> = CALL_SOUND_ROWS
944 .iter()
945 .map(|row| {
946 let on = *(row.field)(&mut current);
947 self.switch_row(row, on)
948 })
949 .collect();
950 let position_center = self.center.clone();
951 let test_center = self.center.clone();
952 v_flex()
953 .w_full()
954 .pt(px(8.))
955 .children(rows)
956 .child(control_row(
957 "Position",
958 "Corner of the main screen",
959 button(corner.label()).on_click(move |_, _, cx| {
960 position_center.update(cx, |center, cx| {
961 center.update_settings(cx, |settings| {
962 settings.corner = settings.corner.next()
963 })
964 });
965 }),
966 ))
967 .child(heading("Sound"))
968 .child(self.switch_row(&NOTIFICATION_SOUND_ROW, sounds.notification_sound))
969 .child(self.alert_sound_row(
970 ("notification-sound", "notification-sound-preview"),
971 "Notification sound",
972 &AlertSound::NORMAL,
973 sounds.notification_sound_type,
974 sounds.notification_sound,
975 |settings| &mut settings.sounds.notification_sound_type,
976 ))
977 .child(self.switch_row(&URGENT_SOUND_ROW, sounds.urgent_sound))
978 .child(self.alert_sound_row(
979 ("urgent-sound", "urgent-sound-preview"),
980 "Urgent sound",
981 &AlertSound::URGENT,
982 sounds.urgent_sound_type,
983 sounds.urgent_sound,
984 |settings| &mut settings.sounds.urgent_sound_type,
985 ))
986 .children(call_sound_rows)
987 .child(h_flex().w_full().px(px(20.)).py(px(12.)).child(
988 button("Send test notification").on_click(move |_, _, cx| {
989 test_center.update(cx, |center, cx| center.send_test_notification(cx));
990 }),
991 ))
992 }
993}
994
995fn ringtone_ids(call_type: RingtoneCallType) -> (&'static str, &'static str) {
996 match call_type {
997 RingtoneCallType::Regular => ("ringtone-regular", "ringtone-regular-preview"),
998 RingtoneCallType::CallGroup => ("ringtone-call-group", "ringtone-call-group-preview"),
999 RingtoneCallType::CallQueue => ("ringtone-call-queue", "ringtone-call-queue-preview"),
1000 RingtoneCallType::Delegate => ("ringtone-delegate", "ringtone-delegate-preview"),
1001 }
1002}