BlueGit

ict rusty-teams

feat(settings): settings as an in-app dialog with Teams section nav

- Large dialog over the main window replaces the separate settings window
- Left nav in Teams order, Agents and MCP in their own group, About pinned at the bottom
- Translation and chat list settings move into General and Chats and channels, avatar menu entries open the dialog at that section
- MCP becomes one page (Server, Access, Install), Devices gains Speaker, Microphone and Make a test call
- Esc and backdrop click close, compact inset below 1100x720
- layout_guard test checks the dialog inset at every size and section

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
0d4fda204ab9513b6e9067c416179d72b98ca346
Parent
413e4e58
26 files changed +1943 −1425
crates/app-state/src/app_state.rs +1 −1
@@ -63,7 +63,7 @@ pub enum AppEvent {
63 63 Forward,
64 64 ImageViewer,
65 65 StatusMessage,
66 NotificationSettings,
66 Settings(crate::settings_section::SettingsSection),
67 67 Profile,
68 68 Call,
69 69 Ring,
@@ -63,7 +63,7 @@ pub enum AppEvent {
63 Forward,
63 Forward,
64 ImageViewer,
64 ImageViewer,
65 StatusMessage,
65 StatusMessage,
66 NotificationSettings,
66 Settings(crate::settings_section::SettingsSection),
67 Profile,
67 Profile,
68 Call,
68 Call,
69 Ring,
69 Ring,
crates/app-state/src/lib.rs +1 −0
@@ -34,6 +34,7 @@ pub mod rows;
34 34 pub mod scheduled;
35 35 pub mod scheduled_rows;
36 36 pub mod section_actions;
37 pub mod settings_section;
37 38 pub mod sidebar_model;
38 39 pub mod sound_actions;
39 40 pub mod stored_outgoing;
@@ -34,6 +34,7 @@ pub mod rows;
34pub mod scheduled;
34pub mod scheduled;
35pub mod scheduled_rows;
35pub mod scheduled_rows;
36pub mod section_actions;
36pub mod section_actions;
37pub mod settings_section;
37pub mod sidebar_model;
38pub mod sidebar_model;
38pub mod sound_actions;
39pub mod sound_actions;
39pub mod stored_outgoing;
40pub mod stored_outgoing;
crates/app-state/src/own_status.rs +0 −4
@@ -298,10 +298,6 @@ impl AppState {
298 298 std::mem::take(&mut self.status_message_request)
299 299 }
300 300
301 pub fn open_notification_settings(&mut self, cx: &mut Context<Self>) {
302 cx.emit(AppEvent::NotificationSettings);
303 }
304
305 301 pub fn refresh_own_status(&mut self, cx: &mut Context<Self>) {
306 302 let Some(engine) = self.engine.clone().filter(|_| !self.mode.demo) else {
307 303 return;
@@ -298,10 +298,6 @@ impl AppState {
298 std::mem::take(&mut self.status_message_request)
298 std::mem::take(&mut self.status_message_request)
299 }
299 }
300
300
301 pub fn open_notification_settings(&mut self, cx: &mut Context<Self>) {
302 cx.emit(AppEvent::NotificationSettings);
303 }
304
305 pub fn refresh_own_status(&mut self, cx: &mut Context<Self>) {
301 pub fn refresh_own_status(&mut self, cx: &mut Context<Self>) {
306 let Some(engine) = self.engine.clone().filter(|_| !self.mode.demo) else {
302 let Some(engine) = self.engine.clone().filter(|_| !self.mode.demo) else {
307 return;
303 return;
crates/app-state/src/settings_section.rs added +21 −0
@@ -0,0 +1,21 @@
1 use gpui_kit::Context;
2
3 use crate::app_state::{AppEvent, AppState};
4
5 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6 pub enum SettingsSection {
7 General,
8 Notifications,
9 Chats,
10 Calls,
11 Devices,
12 Agents,
13 Mcp,
14 About,
15 }
16
17 impl AppState {
18 pub fn open_settings(&mut self, section: SettingsSection, cx: &mut Context<Self>) {
19 cx.emit(AppEvent::Settings(section));
20 }
21 }
@@ -0,0 +1,21 @@
1use gpui_kit::Context;
2
3use crate::app_state::{AppEvent, AppState};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum SettingsSection {
7 General,
8 Notifications,
9 Chats,
10 Calls,
11 Devices,
12 Agents,
13 Mcp,
14 About,
15}
16
17impl AppState {
18 pub fn open_settings(&mut self, section: SettingsSection, cx: &mut Context<Self>) {
19 cx.emit(AppEvent::Settings(section));
20 }
21}
crates/app/src/agents/settings_forms.rs +1 −1
@@ -11,7 +11,7 @@ use super::settings_controls::{
11 11 };
12 12 use super::settings_problems::{agent_problem, command_problem, placeholder_problem};
13 13 use super::settings_section::{AgentsSettings, Probe};
14 use crate::notify::switch;
14 use crate::settings::switch;
15 15 use crate::theme;
16 16 use crate::views::widgets::icon;
17 17
@@ -11,7 +11,7 @@ use super::settings_controls::{
11};
11};
12use super::settings_problems::{agent_problem, command_problem, placeholder_problem};
12use super::settings_problems::{agent_problem, command_problem, placeholder_problem};
13use super::settings_section::{AgentsSettings, Probe};
13use super::settings_section::{AgentsSettings, Probe};
14use crate::notify::switch;
14use crate::settings::switch;
15use crate::theme;
15use crate::theme;
16use crate::views::widgets::icon;
16use crate::views::widgets::icon;
17
17
crates/app/src/agents/settings_section.rs +1 −1
@@ -518,7 +518,7 @@ fn list_row(
518 518 .items_center()
519 519 .rounded(px(8.))
520 520 .cursor_pointer()
521 .hover(|row| row.bg(theme::row_hover()))
521 .hover(|row| row.bg(theme::popup_hover()))
522 522 .children(leading)
523 523 .child(
524 524 v_flex()
@@ -518,7 +518,7 @@ fn list_row(
518 .items_center()
518 .items_center()
519 .rounded(px(8.))
519 .rounded(px(8.))
520 .cursor_pointer()
520 .cursor_pointer()
521 .hover(|row| row.bg(theme::row_hover()))
521 .hover(|row| row.bg(theme::popup_hover()))
522 .children(leading)
522 .children(leading)
523 .child(
523 .child(
524 v_flex()
524 v_flex()
crates/app/src/layout_guard.rs +57 −0
@@ -169,6 +169,8 @@ mod frames {
169 169 use gpui_kit::Entity;
170 170
171 171 use crate::app_state::{AppHandle, AppState, Mode, Selection};
172 use crate::settings::metrics;
173 use crate::settings_section::SettingsSection;
172 174 use crate::call::{ActiveCall, CallModel, ConsultCall};
173 175 use crate::demo;
174 176 use crate::user_activity::UserInput;
@@ -245,6 +247,23 @@ mod frames {
245 247 PROPOSAL_BUTTONS,
246 248 REACTION_PILL,
247 249 ];
250 const SETTINGS_TAGS: &[&str] = &[
251 "settings",
252 "settings/nav",
253 "settings/main",
254 "settings/main/header",
255 "settings/main/body",
256 ];
257 const SETTINGS_SECTIONS: [SettingsSection; 8] = [
258 SettingsSection::General,
259 SettingsSection::Notifications,
260 SettingsSection::Chats,
261 SettingsSection::Calls,
262 SettingsSection::Devices,
263 SettingsSection::Agents,
264 SettingsSection::Mcp,
265 SettingsSection::About,
266 ];
248 267 const SIZES: [(f32, f32); 3] = [(640., 480.), (1280., 800.), (1920., 1080.)];
249 268 const TOLERANCE: f32 = 0.5;
250 269 const KNOWN_VIOLATIONS: &[&str] = &[];
@@ -393,6 +412,7 @@ mod frames {
393 412 &PEOPLE_PANEL,
394 413 ])
395 414 .chain(&AGENT_TAGS)
415 .chain(SETTINGS_TAGS)
396 416 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
397 417 .collect()
398 418 }
@@ -809,6 +829,43 @@ mod frames {
809 829 }
810 830 }
811 831
832 #[gpui_kit::test]
833 fn settings_dialog_keeps_its_inset_at_every_size(cx: &mut TestAppContext) {
834 let (handle, state) = mount_with(cx, true);
835 let mut visual = VisualTestContext::from_window(handle, cx);
836 for (width, height) in SIZES.into_iter().chain([(960., 640.)]) {
837 visual.simulate_resize(size(px(width), px(height)));
838 let window = Bounds {
839 origin: point(px(0.), px(0.)),
840 size: size(px(width), px(height)),
841 };
842 let inset = metrics(width, height).inset;
843 for section in SETTINGS_SECTIONS {
844 visual.update(|_, cx| {
845 state.update(cx, |state, cx| state.open_settings(section, cx))
846 });
847 let tags = collect(&mut visual, Some(SETTINGS_TAGS[0]));
848 let found: Vec<String> = violations(&tags, window, SETTINGS_TAGS)
849 .into_iter()
850 .filter(|(key, _)| key.starts_with("settings"))
851 .map(|(key, message)| format!("{section:?}@{width}x{height}:{key}: {message}"))
852 .collect();
853 assert!(found.is_empty(), "{}", found.join("\n"));
854 let dialog = visual.debug_bounds(SETTINGS_TAGS[0]).expect("settings dialog");
855 let edges = [
856 f32::from(dialog.left()),
857 f32::from(dialog.top()),
858 width - f32::from(dialog.right()),
859 height - f32::from(dialog.bottom()),
860 ];
861 assert!(
862 edges.iter().all(|edge| (edge - inset).abs() <= TOLERANCE),
863 "{section:?}@{width}x{height}: dialog edges {edges:?}, expected {inset}"
864 );
865 }
866 }
867 }
868
812 869 #[gpui_kit::test]
813 870 fn agent_proposals_stay_inside_the_main_island(cx: &mut TestAppContext) {
814 871 let (handle, state) = mount_with(cx, true);
@@ -169,6 +169,8 @@ mod frames {
169 use gpui_kit::Entity;
169 use gpui_kit::Entity;
170
170
171 use crate::app_state::{AppHandle, AppState, Mode, Selection};
171 use crate::app_state::{AppHandle, AppState, Mode, Selection};
172 use crate::settings::metrics;
173 use crate::settings_section::SettingsSection;
172 use crate::call::{ActiveCall, CallModel, ConsultCall};
174 use crate::call::{ActiveCall, CallModel, ConsultCall};
173 use crate::demo;
175 use crate::demo;
174 use crate::user_activity::UserInput;
176 use crate::user_activity::UserInput;
@@ -245,6 +247,23 @@ mod frames {
245 PROPOSAL_BUTTONS,
247 PROPOSAL_BUTTONS,
246 REACTION_PILL,
248 REACTION_PILL,
247 ];
249 ];
250 const SETTINGS_TAGS: &[&str] = &[
251 "settings",
252 "settings/nav",
253 "settings/main",
254 "settings/main/header",
255 "settings/main/body",
256 ];
257 const SETTINGS_SECTIONS: [SettingsSection; 8] = [
258 SettingsSection::General,
259 SettingsSection::Notifications,
260 SettingsSection::Chats,
261 SettingsSection::Calls,
262 SettingsSection::Devices,
263 SettingsSection::Agents,
264 SettingsSection::Mcp,
265 SettingsSection::About,
266 ];
248 const SIZES: [(f32, f32); 3] = [(640., 480.), (1280., 800.), (1920., 1080.)];
267 const SIZES: [(f32, f32); 3] = [(640., 480.), (1280., 800.), (1920., 1080.)];
249 const TOLERANCE: f32 = 0.5;
268 const TOLERANCE: f32 = 0.5;
250 const KNOWN_VIOLATIONS: &[&str] = &[];
269 const KNOWN_VIOLATIONS: &[&str] = &[];
@@ -393,6 +412,7 @@ mod frames {
393 &PEOPLE_PANEL,
412 &PEOPLE_PANEL,
394 ])
413 ])
395 .chain(&AGENT_TAGS)
414 .chain(&AGENT_TAGS)
415 .chain(SETTINGS_TAGS)
396 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
416 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
397 .collect()
417 .collect()
398 }
418 }
@@ -809,6 +829,43 @@ mod frames {
809 }
829 }
810 }
830 }
811
831
832 #[gpui_kit::test]
833 fn settings_dialog_keeps_its_inset_at_every_size(cx: &mut TestAppContext) {
834 let (handle, state) = mount_with(cx, true);
835 let mut visual = VisualTestContext::from_window(handle, cx);
836 for (width, height) in SIZES.into_iter().chain([(960., 640.)]) {
837 visual.simulate_resize(size(px(width), px(height)));
838 let window = Bounds {
839 origin: point(px(0.), px(0.)),
840 size: size(px(width), px(height)),
841 };
842 let inset = metrics(width, height).inset;
843 for section in SETTINGS_SECTIONS {
844 visual.update(|_, cx| {
845 state.update(cx, |state, cx| state.open_settings(section, cx))
846 });
847 let tags = collect(&mut visual, Some(SETTINGS_TAGS[0]));
848 let found: Vec<String> = violations(&tags, window, SETTINGS_TAGS)
849 .into_iter()
850 .filter(|(key, _)| key.starts_with("settings"))
851 .map(|(key, message)| format!("{section:?}@{width}x{height}:{key}: {message}"))
852 .collect();
853 assert!(found.is_empty(), "{}", found.join("\n"));
854 let dialog = visual.debug_bounds(SETTINGS_TAGS[0]).expect("settings dialog");
855 let edges = [
856 f32::from(dialog.left()),
857 f32::from(dialog.top()),
858 width - f32::from(dialog.right()),
859 height - f32::from(dialog.bottom()),
860 ];
861 assert!(
862 edges.iter().all(|edge| (edge - inset).abs() <= TOLERANCE),
863 "{section:?}@{width}x{height}: dialog edges {edges:?}, expected {inset}"
864 );
865 }
866 }
867 }
868
812 #[gpui_kit::test]
869 #[gpui_kit::test]
813 fn agent_proposals_stay_inside_the_main_island(cx: &mut TestAppContext) {
870 fn agent_proposals_stay_inside_the_main_island(cx: &mut TestAppContext) {
814 let (handle, state) = mount_with(cx, true);
871 let (handle, state) = mount_with(cx, true);
crates/app/src/main.rs +1 −0
@@ -8,6 +8,7 @@ pub mod call;
8 8 #[cfg(test)]
9 9 mod layout_guard;
10 10 pub mod notify;
11 mod settings;
11 12 mod views;
12 13
13 14 pub use state::*;
@@ -8,6 +8,7 @@ pub mod call;
8#[cfg(test)]
8#[cfg(test)]
9mod layout_guard;
9mod layout_guard;
10pub mod notify;
10pub mod notify;
11mod settings;
11mod views;
12mod views;
12
13
13pub use state::*;
14pub use state::*;
crates/app/src/notify/center.rs +7 −64
@@ -18,7 +18,6 @@ use super::rules::{
18 18 use super::settings;
19 19 use super::sound_cache::{self, SoundHandle};
20 20 use super::sounds::{CallTone, Ringtone};
21 use super::settings_view::{Section, SettingsView};
22 21 use super::stack::{
23 22 AgentToast, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE, ToastModel, ToastStack,
24 23 };
@@ -29,6 +28,7 @@ use crate::app_state::{AppEvent, AppState, selection_for};
29 28 use crate::call::DemoScene;
30 29 use crate::data::{self, Directory, PresenceKind};
31 30 use crate::runtime;
31 use crate::settings_section::SettingsSection;
32 32 use crate::single_instance;
33 33
34 34 const TICK: Duration = Duration::from_millis(33);
@@ -83,8 +83,6 @@ pub struct NotificationCenter {
83 83 pill: Option<OpenWindow>,
84 84 pill_opening: bool,
85 85 hover_hold: bool,
86 settings_window: Option<AnyWindowHandle>,
87 settings_opening: bool,
88 86 unread_mentions: HashSet<String>,
89 87 tray: Option<Tray>,
90 88 shown_badge: Option<Badge>,
@@ -132,8 +130,6 @@ impl NotificationCenter {
132 130 pill: None,
133 131 pill_opening: false,
134 132 hover_hold: false,
135 settings_window: None,
136 settings_opening: false,
137 133 unread_mentions: HashSet::new(),
138 134 tray,
139 135 shown_badge: None,
@@ -865,7 +861,12 @@ impl NotificationCenter {
865 861 TrayCommand::ToggleDoNotDisturb => self.update_settings(cx, |settings| {
866 862 settings.do_not_disturb = !settings.do_not_disturb
867 863 }),
868 TrayCommand::Settings => self.open_settings(cx),
864 TrayCommand::Settings => {
865 self.raise_main_window(cx);
866 self.app.update(cx, |state, cx| {
867 state.open_settings(SettingsSection::General, cx)
868 });
869 }
869 870 TrayCommand::Quit => cx.quit(),
870 871 }
871 872 }
@@ -1059,64 +1060,6 @@ impl NotificationCenter {
1059 1060 }
1060 1061 }
1061 1062
1062 pub fn open_settings(&mut self, cx: &mut Context<Self>) {
1063 self.show_settings(Section::Notifications, false, cx);
1064 }
1065
1066 pub fn open_agent_settings(&mut self, cx: &mut Context<Self>) {
1067 self.show_settings(Section::Agents, true, cx);
1068 }
1069
1070 fn show_settings(
1071 &mut self,
1072 section: Section,
1073 switch_open_window: bool,
1074 cx: &mut Context<Self>,
1075 ) {
1076 if let Some(handle) = self.settings_window {
1077 let shown = handle.update(cx, |view, window, cx| {
1078 window.activate_window();
1079 if switch_open_window && let Ok(view) = view.downcast::<SettingsView>() {
1080 view.update(cx, |view, cx| view.select_section(section, cx));
1081 }
1082 });
1083 if shown.is_ok() {
1084 return;
1085 }
1086 self.settings_window = None;
1087 }
1088 if self.settings_opening {
1089 return;
1090 }
1091 self.settings_opening = true;
1092 let center = cx.entity();
1093 let options = WindowOptions {
1094 window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
1095 None,
1096 size(px(SettingsView::WIDTH), px(SettingsView::HEIGHT)),
1097 cx,
1098 ))),
1099 titlebar: Some(TitlebarOptions {
1100 title: Some("Settings".into()),
1101 ..Default::default()
1102 }),
1103 is_resizable: false,
1104 is_minimizable: false,
1105 ..Default::default()
1106 };
1107 // open_window draws once right away, and SettingsView reads this entity while rendering.
1108 cx.defer(move |cx| {
1109 let view_center = center.clone();
1110 let opened = gpui_kit::open_window(options, cx, move |window, cx| {
1111 cx.new(|cx| SettingsView::new(view_center, section, window, cx))
1112 });
1113 center.update(cx, |this, _| {
1114 this.settings_opening = false;
1115 this.settings_window = opened.ok().map(|(handle, _)| handle);
1116 });
1117 });
1118 }
1119
1120 1063 pub fn send_test_notification(&mut self, cx: &mut Context<Self>) {
1121 1064 let incoming = Incoming {
1122 1065 conversation_id: "test-notification".to_owned(),
@@ -18,7 +18,6 @@ use super::rules::{
18use super::settings;
18use super::settings;
19use super::sound_cache::{self, SoundHandle};
19use super::sound_cache::{self, SoundHandle};
20use super::sounds::{CallTone, Ringtone};
20use super::sounds::{CallTone, Ringtone};
21use super::settings_view::{Section, SettingsView};
22use super::stack::{
21use super::stack::{
23 AgentToast, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE, ToastModel, ToastStack,
22 AgentToast, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE, ToastModel, ToastStack,
24};
23};
@@ -29,6 +28,7 @@ use crate::app_state::{AppEvent, AppState, selection_for};
29use crate::call::DemoScene;
28use crate::call::DemoScene;
30use crate::data::{self, Directory, PresenceKind};
29use crate::data::{self, Directory, PresenceKind};
31use crate::runtime;
30use crate::runtime;
31use crate::settings_section::SettingsSection;
32use crate::single_instance;
32use crate::single_instance;
33
33
34const TICK: Duration = Duration::from_millis(33);
34const TICK: Duration = Duration::from_millis(33);
@@ -83,8 +83,6 @@ pub struct NotificationCenter {
83 pill: Option<OpenWindow>,
83 pill: Option<OpenWindow>,
84 pill_opening: bool,
84 pill_opening: bool,
85 hover_hold: bool,
85 hover_hold: bool,
86 settings_window: Option<AnyWindowHandle>,
87 settings_opening: bool,
88 unread_mentions: HashSet<String>,
86 unread_mentions: HashSet<String>,
89 tray: Option<Tray>,
87 tray: Option<Tray>,
90 shown_badge: Option<Badge>,
88 shown_badge: Option<Badge>,
@@ -132,8 +130,6 @@ impl NotificationCenter {
132 pill: None,
130 pill: None,
133 pill_opening: false,
131 pill_opening: false,
134 hover_hold: false,
132 hover_hold: false,
135 settings_window: None,
136 settings_opening: false,
137 unread_mentions: HashSet::new(),
133 unread_mentions: HashSet::new(),
138 tray,
134 tray,
139 shown_badge: None,
135 shown_badge: None,
@@ -865,7 +861,12 @@ impl NotificationCenter {
865 TrayCommand::ToggleDoNotDisturb => self.update_settings(cx, |settings| {
861 TrayCommand::ToggleDoNotDisturb => self.update_settings(cx, |settings| {
866 settings.do_not_disturb = !settings.do_not_disturb
862 settings.do_not_disturb = !settings.do_not_disturb
867 }),
863 }),
868 TrayCommand::Settings => self.open_settings(cx),
864 TrayCommand::Settings => {
865 self.raise_main_window(cx);
866 self.app.update(cx, |state, cx| {
867 state.open_settings(SettingsSection::General, cx)
868 });
869 }
869 TrayCommand::Quit => cx.quit(),
870 TrayCommand::Quit => cx.quit(),
870 }
871 }
871 }
872 }
@@ -1059,64 +1060,6 @@ impl NotificationCenter {
1059 }
1060 }
1060 }
1061 }
1061
1062
1062 pub fn open_settings(&mut self, cx: &mut Context<Self>) {
1063 self.show_settings(Section::Notifications, false, cx);
1064 }
1065
1066 pub fn open_agent_settings(&mut self, cx: &mut Context<Self>) {
1067 self.show_settings(Section::Agents, true, cx);
1068 }
1069
1070 fn show_settings(
1071 &mut self,
1072 section: Section,
1073 switch_open_window: bool,
1074 cx: &mut Context<Self>,
1075 ) {
1076 if let Some(handle) = self.settings_window {
1077 let shown = handle.update(cx, |view, window, cx| {
1078 window.activate_window();
1079 if switch_open_window && let Ok(view) = view.downcast::<SettingsView>() {
1080 view.update(cx, |view, cx| view.select_section(section, cx));
1081 }
1082 });
1083 if shown.is_ok() {
1084 return;
1085 }
1086 self.settings_window = None;
1087 }
1088 if self.settings_opening {
1089 return;
1090 }
1091 self.settings_opening = true;
1092 let center = cx.entity();
1093 let options = WindowOptions {
1094 window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
1095 None,
1096 size(px(SettingsView::WIDTH), px(SettingsView::HEIGHT)),
1097 cx,
1098 ))),
1099 titlebar: Some(TitlebarOptions {
1100 title: Some("Settings".into()),
1101 ..Default::default()
1102 }),
1103 is_resizable: false,
1104 is_minimizable: false,
1105 ..Default::default()
1106 };
1107 // open_window draws once right away, and SettingsView reads this entity while rendering.
1108 cx.defer(move |cx| {
1109 let view_center = center.clone();
1110 let opened = gpui_kit::open_window(options, cx, move |window, cx| {
1111 cx.new(|cx| SettingsView::new(view_center, section, window, cx))
1112 });
1113 center.update(cx, |this, _| {
1114 this.settings_opening = false;
1115 this.settings_window = opened.ok().map(|(handle, _)| handle);
1116 });
1117 });
1118 }
1119
1120 pub fn send_test_notification(&mut self, cx: &mut Context<Self>) {
1063 pub fn send_test_notification(&mut self, cx: &mut Context<Self>) {
1121 let incoming = Incoming {
1064 let incoming = Incoming {
1122 conversation_id: "test-notification".to_owned(),
1065 conversation_id: "test-notification".to_owned(),
crates/app/src/notify/mod.rs +0 −3
@@ -2,10 +2,7 @@ mod agent_toast;
2 2 mod center;
3 3 mod meeting_view;
4 4 mod ring_view;
5 mod settings_mcp;
6 mod settings_view;
7 5 mod toast;
8 6
9 7 pub use state::notify::*;
10 8 pub use center::NotificationCenter;
11 pub(crate) use settings_view::switch;
@@ -2,10 +2,7 @@ mod agent_toast;
2mod center;
2mod center;
3mod meeting_view;
3mod meeting_view;
4mod ring_view;
4mod ring_view;
5mod settings_mcp;
6mod settings_view;
7mod toast;
5mod toast;
8
6
9pub use state::notify::*;
7pub use state::notify::*;
10pub use center::NotificationCenter;
8pub use center::NotificationCenter;
11pub(crate) use settings_view::switch;
crates/app/src/notify/settings_view.rs deleted +0 −1002
@@ -1,1002 +0,0 @@
1 use std::time::{Duration, Instant};
2
3 use calling::camera::{DEFAULT_CAMERA_LABEL, list_cameras};
4 use calling::{CameraEffects, DeviceChoice, DeviceEntry, MicSettings, NoiseSuppression, camera_entries};
5 use gpui_kit::assets::IconName;
6 use gpui_kit::component::{
7 button::Button,
8 h_flex,
9 menu::{DropdownMenu as _, PopupMenuItem},
10 v_flex,
11 };
12 use gpui_kit::base::Disableable as _;
13 use gpui_kit::prelude::FluentBuilder as _;
14 use gpui_kit::*;
15
16 use super::center::NotificationCenter;
17 use super::sounds::{AlertSound, Ringtone, RingtoneCallType};
18 use super::rules::Settings;
19 use super::settings_mcp::McpView;
20 use crate::agents::AgentsSettings;
21 use crate::app_state::AppState;
22 use crate::call::{BackgroundPick, CameraPreview, preview_backgrounds};
23 use crate::theme;
24
25 const FPS_TICK: Duration = Duration::from_millis(500);
26 const SELECT_WIDTH: f32 = 170.;
27 const SOUND_SELECT_WIDTH: f32 = 124.;
28 const PREVIEW_WIDTH: f32 = 380.;
29 const PREVIEW_HEIGHT: f32 = 214.;
30 const PREVIEW_RADIUS: f32 = 10.;
31 const SOFT_FOCUS_LEVELS: [(&str, u8); 3] = [("Low", 25), ("Medium", 50), ("High", 75)];
32 const CAMERA_IN_USE: &str = "Camera is in use by the call";
33
34 fn camera_in_call(state: &AppState) -> bool {
35 state.call.is_some()
36 }
37
38 #[derive(Clone, Copy, PartialEq, Eq)]
39 pub(super) enum Section {
40 Notifications,
41 Calls,
42 Devices,
43 Agents,
44 Mcp,
45 }
46
47 impl 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
67 type Accessor = fn(&mut Settings) -> &mut bool;
68
69 struct Row {
70 title: &'static str,
71 detail: &'static str,
72 field: Accessor,
73 }
74
75 const 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
103 const NOTIFICATION_SOUND_ROW: Row = Row {
104 title: "Play sounds with notifications",
105 detail: "",
106 field: |settings| &mut settings.sounds.notification_sound,
107 };
108
109 const 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
115 const 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
128 type SoundAccessor = fn(&mut Settings) -> &mut AlertSound;
129
130 pub 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
146 impl 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
394 pub(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
417 fn button(label: &'static str) -> Stateful<Div> {
418 button_with_id(label, label)
419 }
420
421 fn 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
439 fn titled(title: &'static str, detail: impl Into<SharedString>) -> Div {
440 titled_with(title, detail, theme::text_muted())
441 }
442
443 pub(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
472 pub(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
487 fn 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
509 fn 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
521 fn 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
546 impl 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
891 impl 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
931 impl 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
995 fn 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 }
@@ -1,1002 +0,0 @@
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}
crates/app/src/settings/about.rs added +25 −0
@@ -0,0 +1,25 @@
1 use gpui_kit::component::v_flex;
2 use gpui_kit::*;
3
4 use super::rows::{caption, control_row, text_button};
5 use crate::{format, updater};
6
7 pub fn render() -> Div {
8 let build_id = updater::running_version();
9 let copied = build_id.to_owned();
10 v_flex()
11 .w_full()
12 .child(caption("RUSTY TEAMS"))
13 .child(control_row(
14 "Version",
15 format::short_version(build_id, env!("CARGO_PKG_VERSION")),
16 div(),
17 ))
18 .child(control_row(
19 "Build",
20 build_id.to_owned(),
21 text_button("settings-copy-build", "Copy").on_click(move |_, _, cx| {
22 cx.write_to_clipboard(ClipboardItem::new_string(copied.clone()))
23 }),
24 ))
25 }
@@ -0,0 +1,25 @@
1use gpui_kit::component::v_flex;
2use gpui_kit::*;
3
4use super::rows::{caption, control_row, text_button};
5use crate::{format, updater};
6
7pub fn render() -> Div {
8 let build_id = updater::running_version();
9 let copied = build_id.to_owned();
10 v_flex()
11 .w_full()
12 .child(caption("RUSTY TEAMS"))
13 .child(control_row(
14 "Version",
15 format::short_version(build_id, env!("CARGO_PKG_VERSION")),
16 div(),
17 ))
18 .child(control_row(
19 "Build",
20 build_id.to_owned(),
21 text_button("settings-copy-build", "Copy").on_click(move |_, _, cx| {
22 cx.write_to_clipboard(ClipboardItem::new_string(copied.clone()))
23 }),
24 ))
25}
crates/app/src/settings/calls.rs added +64 −0
@@ -0,0 +1,64 @@
1 use gpui_kit::component::{h_flex, v_flex};
2 use gpui_kit::*;
3
4 use super::rows::{Choice, caption, control_row, select, text_button};
5 use crate::notify::NotificationCenter;
6 use crate::notify::sounds::{Ringtone, RingtoneCallType};
7
8 pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
9 let ringtones = center.read(cx).settings().sounds.ringtones;
10 let rows = RingtoneCallType::ALL
11 .into_iter()
12 .filter(|call_type| {
13 *call_type == RingtoneCallType::Regular || ringtones.get(*call_type) != Ringtone::Ring
14 })
15 .map(|call_type| ringtone_row(center, call_type, ringtones.get(call_type)));
16 v_flex().w_full().child(caption("RINGTONES")).children(rows)
17 }
18
19 fn ringtone_row(
20 center: &Entity<NotificationCenter>,
21 call_type: RingtoneCallType,
22 current: Ringtone,
23 ) -> Div {
24 let choices = Ringtone::ALL
25 .iter()
26 .map(|ringtone| {
27 let (center, ringtone) = (center.clone(), *ringtone);
28 Choice::new(ringtone.label(), ringtone == current, move |cx| {
29 center.update(cx, |center, cx| {
30 center.update_settings(cx, |settings| {
31 settings.sounds.ringtones.set(call_type, ringtone)
32 });
33 center.preview_sound(ringtone.file_name(), cx);
34 })
35 })
36 })
37 .collect();
38 let (id, preview_id) = ringtone_ids(call_type);
39 let preview_center = center.clone();
40 control_row(
41 call_type.label(),
42 "",
43 h_flex()
44 .gap(px(8.))
45 .items_center()
46 .child(select(id, current.label(), false, choices))
47 .child(
48 text_button(preview_id, "Preview").on_click(move |_, _, cx| {
49 preview_center.update(cx, |center, cx| {
50 center.preview_sound(current.file_name(), cx)
51 })
52 }),
53 ),
54 )
55 }
56
57 fn ringtone_ids(call_type: RingtoneCallType) -> (&'static str, &'static str) {
58 match call_type {
59 RingtoneCallType::Regular => ("ringtone-regular", "ringtone-regular-preview"),
60 RingtoneCallType::CallGroup => ("ringtone-call-group", "ringtone-call-group-preview"),
61 RingtoneCallType::CallQueue => ("ringtone-call-queue", "ringtone-call-queue-preview"),
62 RingtoneCallType::Delegate => ("ringtone-delegate", "ringtone-delegate-preview"),
63 }
64 }
@@ -0,0 +1,64 @@
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::*;
3
4use super::rows::{Choice, caption, control_row, select, text_button};
5use crate::notify::NotificationCenter;
6use crate::notify::sounds::{Ringtone, RingtoneCallType};
7
8pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
9 let ringtones = center.read(cx).settings().sounds.ringtones;
10 let rows = RingtoneCallType::ALL
11 .into_iter()
12 .filter(|call_type| {
13 *call_type == RingtoneCallType::Regular || ringtones.get(*call_type) != Ringtone::Ring
14 })
15 .map(|call_type| ringtone_row(center, call_type, ringtones.get(call_type)));
16 v_flex().w_full().child(caption("RINGTONES")).children(rows)
17}
18
19fn ringtone_row(
20 center: &Entity<NotificationCenter>,
21 call_type: RingtoneCallType,
22 current: Ringtone,
23) -> Div {
24 let choices = Ringtone::ALL
25 .iter()
26 .map(|ringtone| {
27 let (center, ringtone) = (center.clone(), *ringtone);
28 Choice::new(ringtone.label(), ringtone == current, move |cx| {
29 center.update(cx, |center, cx| {
30 center.update_settings(cx, |settings| {
31 settings.sounds.ringtones.set(call_type, ringtone)
32 });
33 center.preview_sound(ringtone.file_name(), cx);
34 })
35 })
36 })
37 .collect();
38 let (id, preview_id) = ringtone_ids(call_type);
39 let preview_center = center.clone();
40 control_row(
41 call_type.label(),
42 "",
43 h_flex()
44 .gap(px(8.))
45 .items_center()
46 .child(select(id, current.label(), false, choices))
47 .child(
48 text_button(preview_id, "Preview").on_click(move |_, _, cx| {
49 preview_center.update(cx, |center, cx| {
50 center.preview_sound(current.file_name(), cx)
51 })
52 }),
53 ),
54 )
55}
56
57fn ringtone_ids(call_type: RingtoneCallType) -> (&'static str, &'static str) {
58 match call_type {
59 RingtoneCallType::Regular => ("ringtone-regular", "ringtone-regular-preview"),
60 RingtoneCallType::CallGroup => ("ringtone-call-group", "ringtone-call-group-preview"),
61 RingtoneCallType::CallQueue => ("ringtone-call-queue", "ringtone-call-queue-preview"),
62 RingtoneCallType::Delegate => ("ringtone-delegate", "ringtone-delegate-preview"),
63 }
64}
crates/app/src/settings/chats.rs added +30 −0
@@ -0,0 +1,30 @@
1 use gpui_kit::component::v_flex;
2 use gpui_kit::*;
3 use teams_core::ChatSection;
4
5 use super::rows::{caption, toggle_row};
6 use crate::app_state::AppState;
7 use crate::theme;
8
9 pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
10 let enabled = app
11 .read(cx)
12 .directory
13 .section_settings
14 .enabled(ChatSection::Muted);
15 let toggle_app = app.clone();
16 v_flex().w_full().child(caption("CHAT LIST")).child(
17 toggle_row(
18 "settings-muted-section",
19 "Show muted items in their own section",
20 "Read from your Teams account",
21 theme::text_muted(),
22 enabled,
23 )
24 .on_click(move |_, _, cx| {
25 toggle_app.update(cx, |state, cx| {
26 state.set_chat_section(ChatSection::Muted, !enabled, cx)
27 })
28 }),
29 )
30 }
@@ -0,0 +1,30 @@
1use gpui_kit::component::v_flex;
2use gpui_kit::*;
3use teams_core::ChatSection;
4
5use super::rows::{caption, toggle_row};
6use crate::app_state::AppState;
7use crate::theme;
8
9pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
10 let enabled = app
11 .read(cx)
12 .directory
13 .section_settings
14 .enabled(ChatSection::Muted);
15 let toggle_app = app.clone();
16 v_flex().w_full().child(caption("CHAT LIST")).child(
17 toggle_row(
18 "settings-muted-section",
19 "Show muted items in their own section",
20 "Read from your Teams account",
21 theme::text_muted(),
22 enabled,
23 )
24 .on_click(move |_, _, cx| {
25 toggle_app.update(cx, |state, cx| {
26 state.set_chat_section(ChatSection::Muted, !enabled, cx)
27 })
28 }),
29 )
30}
crates/app/src/settings/devices.rs added +525 −0
@@ -0,0 +1,525 @@
1 use std::time::{Duration, Instant};
2
3 use calling::camera::{DEFAULT_CAMERA_LABEL, list_cameras};
4 use calling::devices::{DeviceLists, list_devices, shared_factory};
5 use calling::{
6 CameraEffects, DeviceChoice, DeviceEntry, MicSettings, NoiseSuppression, camera_entries,
7 };
8 use gpui_kit::component::{h_flex, v_flex};
9 use gpui_kit::prelude::FluentBuilder as _;
10 use gpui_kit::*;
11
12 use super::rows::{Choice, caption, control_row, row, select, text_button, toggle_row};
13 use crate::app_state::AppState;
14 use crate::call::{BackgroundPick, CameraPreview, preview_backgrounds};
15 use crate::theme;
16 use crate::views::prejoin_view::demo_devices;
17
18 const FPS_TICK: Duration = Duration::from_millis(500);
19 const PREVIEW_WIDTH: f32 = 288.;
20 const PREVIEW_HEIGHT: f32 = 162.;
21 const PREVIEW_RADIUS: f32 = 10.;
22 const SOFT_FOCUS_LEVELS: [(&str, u8); 3] = [("Low", 25), ("Medium", 50), ("High", 75)];
23 const CAMERA_IN_USE: &str = "Camera is in use by the call";
24 const DEFAULT_DEVICE_LABEL: &str = "Default device";
25
26 struct Effect {
27 id: &'static str,
28 title: &'static str,
29 read: fn(&CameraEffects) -> bool,
30 flip: fn(&mut CameraEffects),
31 }
32
33 const EFFECTS: [Effect; 4] = [
34 Effect {
35 id: "effect-mirror",
36 title: "Mirror my video",
37 read: |effects| effects.mirror,
38 flip: |effects| effects.mirror = !effects.mirror,
39 },
40 Effect {
41 id: "effect-framing",
42 title: "Auto framing",
43 read: |effects| effects.auto_framing,
44 flip: |effects| effects.auto_framing = !effects.auto_framing,
45 },
46 Effect {
47 id: "effect-brightness",
48 title: "Adjust brightness",
49 read: |effects| effects.adjust_brightness,
50 flip: |effects| effects.adjust_brightness = !effects.adjust_brightness,
51 },
52 Effect {
53 id: "effect-soft-focus",
54 title: "Soft focus",
55 read: |effects| effects.soft_focus,
56 flip: |effects| effects.soft_focus = !effects.soft_focus,
57 },
58 ];
59
60 fn camera_in_call(state: &AppState) -> bool {
61 state.call.is_some()
62 }
63
64 fn label_of(entries: &[DeviceEntry], choice: &DeviceChoice, fallback: &str) -> String {
65 entries
66 .iter()
67 .find(|entry| &entry.choice == choice)
68 .map_or_else(|| fallback.to_owned(), |entry| entry.label.clone())
69 }
70
71 pub struct DevicesView {
72 app: Entity<AppState>,
73 preview: CameraPreview,
74 cameras: Vec<DeviceEntry>,
75 audio_devices: DeviceLists,
76 camera: DeviceChoice,
77 background: BackgroundPick,
78 preview_blocked: bool,
79 _app_subscription: Subscription,
80 _release: Subscription,
81 }
82
83 impl DevicesView {
84 pub fn new(app: Entity<AppState>, cx: &mut Context<Self>) -> Self {
85 let app_subscription = cx.observe(&app, |view, _, cx| view.sync_preview_block(cx));
86 let release = cx.on_release(|view, cx| view.preview.stop(cx));
87 let (preview, mut updates) = CameraPreview::new();
88 let state = app.read(cx);
89 let demo = state.mode.demo;
90 let camera = state.call_camera.clone();
91 preview.set_effects(state.call_effects);
92 let preview_blocked = camera_in_call(state);
93 let background = Some(state.call_background.clone())
94 .filter(|pick| {
95 preview_backgrounds(&state.call_backgrounds)
96 .iter()
97 .any(|(known, _)| known == pick)
98 })
99 .unwrap_or_default();
100 cx.spawn(async move |this, cx| {
101 while updates.recv().await.is_some() {
102 if this.update(cx, |view, cx| view.take_frames(cx)).is_err() {
103 return;
104 }
105 }
106 })
107 .detach();
108 cx.spawn(async move |this, cx| {
109 loop {
110 cx.background_executor().timer(FPS_TICK).await;
111 let ticked = this.update(cx, |view, cx| {
112 view.preview.tick(Instant::now());
113 cx.notify();
114 });
115 if ticked.is_err() {
116 break;
117 }
118 }
119 })
120 .detach();
121 let mut view = DevicesView {
122 app,
123 preview,
124 cameras: camera_entries(&[]),
125 audio_devices: if demo {
126 demo_devices()
127 } else {
128 DeviceLists::default()
129 },
130 camera,
131 background,
132 preview_blocked,
133 _app_subscription: app_subscription,
134 _release: release,
135 };
136 view.load_devices(demo, cx);
137 view.apply_background(cx);
138 view.start_preview();
139 view
140 }
141
142 fn take_frames(&mut self, cx: &mut Context<Self>) {
143 self.preview.take_frames(cx);
144 cx.notify();
145 }
146
147 fn load_devices(&mut self, demo: bool, cx: &mut Context<Self>) {
148 cx.spawn(async move |this, cx| {
149 let (cameras, audio_devices) = cx
150 .background_executor()
151 .spawn(async move {
152 let audio_devices = (!demo).then(|| list_devices(&shared_factory()));
153 (list_cameras(), audio_devices)
154 })
155 .await;
156 this.update(cx, |view, cx| {
157 view.cameras = camera_entries(&cameras);
158 if let Some(audio_devices) = audio_devices {
159 view.audio_devices = audio_devices;
160 }
161 cx.notify();
162 })
163 .ok();
164 })
165 .detach();
166 }
167
168 fn start_preview(&mut self) {
169 if !self.preview_blocked {
170 self.preview.start(&self.camera);
171 }
172 }
173
174 fn sync_preview_block(&mut self, cx: &mut Context<Self>) {
175 let blocked = camera_in_call(self.app.read(cx));
176 if blocked == self.preview_blocked {
177 return;
178 }
179 self.preview_blocked = blocked;
180 if blocked {
181 self.preview.stop(cx);
182 } else {
183 self.start_preview();
184 }
185 cx.notify();
186 }
187
188 fn select_camera(&mut self, camera: DeviceChoice, cx: &mut Context<Self>) {
189 self.camera = camera.clone();
190 self.app
191 .update(cx, |state, cx| state.select_call_camera(camera, cx));
192 self.start_preview();
193 cx.notify();
194 }
195
196 fn select_background(&mut self, pick: BackgroundPick, cx: &mut Context<Self>) {
197 self.background = pick.clone();
198 self.app
199 .update(cx, |state, cx| state.set_call_background(pick, cx));
200 self.apply_background(cx);
201 cx.notify();
202 }
203
204 fn apply_background(&self, cx: &App) {
205 let state = self.app.read(cx);
206 if let Some(choice) = state.call_backgrounds.choice_for(&self.background) {
207 self.preview.set_background(choice);
208 }
209 }
210
211 fn set_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) {
212 self.app
213 .update(cx, |state, cx| state.set_call_mic(settings, cx));
214 cx.notify();
215 }
216
217 fn set_effects(&mut self, effects: CameraEffects, cx: &mut Context<Self>) {
218 self.preview.set_effects(effects);
219 self.app
220 .update(cx, |state, cx| state.set_call_effects(effects, cx));
221 cx.notify();
222 }
223
224 fn preview_status(&self) -> String {
225 if self.preview_blocked {
226 return CAMERA_IN_USE.to_owned();
227 }
228 match self.preview.failure() {
229 Some(reason) => format!("Camera could not start: {reason}"),
230 None => self
231 .preview
232 .fps()
233 .map_or("Starting camera...".to_owned(), |fps| {
234 format!("{fps:.0} fps")
235 }),
236 }
237 }
238
239 fn audio_rows(&self, cx: &mut Context<Self>) -> Vec<AnyElement> {
240 let view = cx.entity();
241 let state = self.app.read(cx);
242 let (input, output, mic) = (
243 state.call_input.clone(),
244 state.call_output.clone(),
245 state.call_mic,
246 );
247 let device_choices = |entries: Vec<DeviceEntry>, current: &DeviceChoice, output: bool| {
248 entries
249 .into_iter()
250 .map(|entry| {
251 let (app, choice) = (self.app.clone(), entry.choice.clone());
252 Choice::new(entry.label, &entry.choice == current, move |cx| {
253 let choice = choice.clone();
254 app.update(cx, |state, cx| {
255 if output {
256 state.select_call_output(choice, cx)
257 } else {
258 state.select_call_input(choice, cx)
259 }
260 })
261 })
262 })
263 .collect::<Vec<_>>()
264 };
265 let (outputs, inputs) = (
266 self.audio_devices.output_entries(),
267 self.audio_devices.input_entries(),
268 );
269 let speaker_label = label_of(&outputs, &output, DEFAULT_DEVICE_LABEL);
270 let microphone_label = label_of(&inputs, &input, DEFAULT_DEVICE_LABEL);
271 let noise_choices = NoiseSuppression::ALL
272 .iter()
273 .map(|level| {
274 let (view, level) = (view.clone(), *level);
275 Choice::new(level.label(), level == mic.noise_suppression, move |cx| {
276 view.update(cx, |view, cx| {
277 view.set_mic(
278 MicSettings {
279 noise_suppression: level,
280 ..mic
281 },
282 cx,
283 )
284 })
285 })
286 })
287 .collect();
288 let music_view = view.clone();
289 let call_app = self.app.clone();
290 vec![
291 control_row(
292 "Speaker",
293 "",
294 select(
295 "settings-speaker",
296 speaker_label,
297 false,
298 device_choices(outputs, &output, true),
299 ),
300 )
301 .into_any_element(),
302 control_row(
303 "Microphone",
304 "",
305 select(
306 "settings-microphone",
307 microphone_label,
308 false,
309 device_choices(inputs, &input, false),
310 ),
311 )
312 .into_any_element(),
313 control_row(
314 "Noise suppression",
315 if mic.music_mode {
316 "Off while music mode is on"
317 } else {
318 "Echo, hum and background noise"
319 },
320 select(
321 "noise-suppression-select",
322 mic.noise_suppression.label(),
323 mic.music_mode,
324 noise_choices,
325 ),
326 )
327 .into_any_element(),
328 toggle_row(
329 "music-mode-row",
330 "Music mode",
331 "Keeps echo cancellation, turns off the rest",
332 theme::text_muted(),
333 mic.music_mode,
334 )
335 .on_click(move |_, _, cx| {
336 music_view.update(cx, |view, cx| {
337 view.set_mic(
338 MicSettings {
339 music_mode: !mic.music_mode,
340 ..mic
341 },
342 cx,
343 )
344 })
345 })
346 .into_any_element(),
347 control_row(
348 "Make a test call",
349 "Echo bot, checks your speaker and microphone",
350 text_button("settings-test-call", "Make a test call").on_click(move |_, _, cx| {
351 call_app.update(cx, |state, cx| state.start_test_call(cx))
352 }),
353 )
354 .into_any_element(),
355 ]
356 }
357
358 fn camera_block(&self, cx: &mut Context<Self>) -> Div {
359 let view = cx.entity();
360 let camera_label = label_of(&self.cameras, &self.camera, DEFAULT_CAMERA_LABEL);
361 let camera_choices = self
362 .cameras
363 .iter()
364 .map(|entry| {
365 let (view, choice) = (view.clone(), entry.choice.clone());
366 Choice::new(
367 entry.label.clone(),
368 entry.choice == self.camera,
369 move |cx| view.update(cx, |view, cx| view.select_camera(choice.clone(), cx)),
370 )
371 })
372 .collect();
373 let backgrounds = preview_backgrounds(&self.app.read(cx).call_backgrounds);
374 let background_label = backgrounds
375 .iter()
376 .find(|(pick, _)| *pick == self.background)
377 .map_or("None".to_owned(), |(_, label)| label.clone());
378 let background_choices = backgrounds
379 .into_iter()
380 .map(|(pick, label)| {
381 let view = view.clone();
382 let checked = pick == self.background;
383 Choice::new(label, checked, move |cx| {
384 view.update(cx, |view, cx| view.select_background(pick.clone(), cx))
385 })
386 })
387 .collect();
388 let image = self.preview.image(Instant::now());
389 v_flex()
390 .w_full()
391 .child(
392 row()
393 .items_start()
394 .flex_wrap()
395 .child(
396 div()
397 .w(px(PREVIEW_WIDTH))
398 .h(px(PREVIEW_HEIGHT))
399 .flex_none()
400 .flex()
401 .items_center()
402 .justify_center()
403 .overflow_hidden()
404 .rounded(px(PREVIEW_RADIUS))
405 .bg(theme::surface())
406 .children(image.map(|image| {
407 img(ImageSource::Render(image))
408 .size_full()
409 .object_fit(ObjectFit::Cover)
410 .rounded(px(PREVIEW_RADIUS))
411 })),
412 )
413 .child(
414 v_flex()
415 .gap(px(12.))
416 .child(device_label("Camera"))
417 .child(select("camera-select", camera_label, false, camera_choices))
418 .child(device_label("Background"))
419 .child(select(
420 "background-select",
421 background_label,
422 false,
423 background_choices,
424 )),
425 ),
426 )
427 .child(
428 div()
429 .px(px(super::rows::ROW_INSET))
430 .text_size(px(12.))
431 .text_color(theme::text_muted())
432 .child(self.preview_status()),
433 )
434 }
435
436 fn effect_rows(&self, cx: &mut Context<Self>) -> Vec<AnyElement> {
437 let effects = self.app.read(cx).call_effects;
438 let mut rows: Vec<AnyElement> = EFFECTS
439 .iter()
440 .map(|effect| {
441 let view = cx.entity();
442 let flip = effect.flip;
443 toggle_row(
444 effect.id,
445 effect.title,
446 "",
447 theme::text_muted(),
448 (effect.read)(&effects),
449 )
450 .on_click(move |_, _, cx| {
451 view.update(cx, |view, cx| {
452 let mut changed = view.app.read(cx).call_effects;
453 flip(&mut changed);
454 view.set_effects(changed, cx)
455 })
456 })
457 .into_any_element()
458 })
459 .collect();
460 if effects.soft_focus {
461 rows.push(self.strength_row(effects, cx).into_any_element());
462 }
463 rows
464 }
465
466 fn strength_row(&self, effects: CameraEffects, cx: &mut Context<Self>) -> Div {
467 let levels = SOFT_FOCUS_LEVELS.map(|(label, level)| {
468 let view = cx.entity();
469 text_button(label, label)
470 .when(effects.soft_focus_strength == level, |button| {
471 button.bg(theme::accent()).text_color(theme::on_accent())
472 })
473 .on_click(move |_, _, cx| {
474 view.update(cx, |view, cx| {
475 let changed = CameraEffects {
476 soft_focus_strength: level,
477 ..view.app.read(cx).call_effects
478 };
479 view.set_effects(changed, cx)
480 })
481 })
482 });
483 control_row(
484 "Soft focus strength",
485 "",
486 h_flex().gap(px(8.)).children(levels),
487 )
488 }
489 }
490
491 fn device_label(text: &'static str) -> Div {
492 div()
493 .text_size(px(12.))
494 .text_color(theme::text_muted())
495 .child(text)
496 }
497
498 impl Render for DevicesView {
499 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
500 let report_on = self.app.read(cx).call_report_enabled;
501 let report_app = self.app.clone();
502 v_flex()
503 .w_full()
504 .child(caption("AUDIO DEVICES"))
505 .children(self.audio_rows(cx))
506 .child(caption("CAMERA"))
507 .child(self.camera_block(cx))
508 .children(self.effect_rows(cx))
509 .child(caption("DIAGNOSTICS"))
510 .child(
511 toggle_row(
512 "call-report-row",
513 "Save a test report after each call",
514 "Pseudonymized, stays on this computer",
515 theme::text_muted(),
516 report_on,
517 )
518 .on_click(move |_, _, cx| {
519 report_app.update(cx, |state, cx| {
520 state.set_call_report_enabled(!report_on, cx)
521 })
522 }),
523 )
524 }
525 }
@@ -0,0 +1,525 @@
1use std::time::{Duration, Instant};
2
3use calling::camera::{DEFAULT_CAMERA_LABEL, list_cameras};
4use calling::devices::{DeviceLists, list_devices, shared_factory};
5use calling::{
6 CameraEffects, DeviceChoice, DeviceEntry, MicSettings, NoiseSuppression, camera_entries,
7};
8use gpui_kit::component::{h_flex, v_flex};
9use gpui_kit::prelude::FluentBuilder as _;
10use gpui_kit::*;
11
12use super::rows::{Choice, caption, control_row, row, select, text_button, toggle_row};
13use crate::app_state::AppState;
14use crate::call::{BackgroundPick, CameraPreview, preview_backgrounds};
15use crate::theme;
16use crate::views::prejoin_view::demo_devices;
17
18const FPS_TICK: Duration = Duration::from_millis(500);
19const PREVIEW_WIDTH: f32 = 288.;
20const PREVIEW_HEIGHT: f32 = 162.;
21const PREVIEW_RADIUS: f32 = 10.;
22const SOFT_FOCUS_LEVELS: [(&str, u8); 3] = [("Low", 25), ("Medium", 50), ("High", 75)];
23const CAMERA_IN_USE: &str = "Camera is in use by the call";
24const DEFAULT_DEVICE_LABEL: &str = "Default device";
25
26struct Effect {
27 id: &'static str,
28 title: &'static str,
29 read: fn(&CameraEffects) -> bool,
30 flip: fn(&mut CameraEffects),
31}
32
33const EFFECTS: [Effect; 4] = [
34 Effect {
35 id: "effect-mirror",
36 title: "Mirror my video",
37 read: |effects| effects.mirror,
38 flip: |effects| effects.mirror = !effects.mirror,
39 },
40 Effect {
41 id: "effect-framing",
42 title: "Auto framing",
43 read: |effects| effects.auto_framing,
44 flip: |effects| effects.auto_framing = !effects.auto_framing,
45 },
46 Effect {
47 id: "effect-brightness",
48 title: "Adjust brightness",
49 read: |effects| effects.adjust_brightness,
50 flip: |effects| effects.adjust_brightness = !effects.adjust_brightness,
51 },
52 Effect {
53 id: "effect-soft-focus",
54 title: "Soft focus",
55 read: |effects| effects.soft_focus,
56 flip: |effects| effects.soft_focus = !effects.soft_focus,
57 },
58];
59
60fn camera_in_call(state: &AppState) -> bool {
61 state.call.is_some()
62}
63
64fn label_of(entries: &[DeviceEntry], choice: &DeviceChoice, fallback: &str) -> String {
65 entries
66 .iter()
67 .find(|entry| &entry.choice == choice)
68 .map_or_else(|| fallback.to_owned(), |entry| entry.label.clone())
69}
70
71pub struct DevicesView {
72 app: Entity<AppState>,
73 preview: CameraPreview,
74 cameras: Vec<DeviceEntry>,
75 audio_devices: DeviceLists,
76 camera: DeviceChoice,
77 background: BackgroundPick,
78 preview_blocked: bool,
79 _app_subscription: Subscription,
80 _release: Subscription,
81}
82
83impl DevicesView {
84 pub fn new(app: Entity<AppState>, cx: &mut Context<Self>) -> Self {
85 let app_subscription = cx.observe(&app, |view, _, cx| view.sync_preview_block(cx));
86 let release = cx.on_release(|view, cx| view.preview.stop(cx));
87 let (preview, mut updates) = CameraPreview::new();
88 let state = app.read(cx);
89 let demo = state.mode.demo;
90 let camera = state.call_camera.clone();
91 preview.set_effects(state.call_effects);
92 let preview_blocked = camera_in_call(state);
93 let background = Some(state.call_background.clone())
94 .filter(|pick| {
95 preview_backgrounds(&state.call_backgrounds)
96 .iter()
97 .any(|(known, _)| known == pick)
98 })
99 .unwrap_or_default();
100 cx.spawn(async move |this, cx| {
101 while updates.recv().await.is_some() {
102 if this.update(cx, |view, cx| view.take_frames(cx)).is_err() {
103 return;
104 }
105 }
106 })
107 .detach();
108 cx.spawn(async move |this, cx| {
109 loop {
110 cx.background_executor().timer(FPS_TICK).await;
111 let ticked = this.update(cx, |view, cx| {
112 view.preview.tick(Instant::now());
113 cx.notify();
114 });
115 if ticked.is_err() {
116 break;
117 }
118 }
119 })
120 .detach();
121 let mut view = DevicesView {
122 app,
123 preview,
124 cameras: camera_entries(&[]),
125 audio_devices: if demo {
126 demo_devices()
127 } else {
128 DeviceLists::default()
129 },
130 camera,
131 background,
132 preview_blocked,
133 _app_subscription: app_subscription,
134 _release: release,
135 };
136 view.load_devices(demo, cx);
137 view.apply_background(cx);
138 view.start_preview();
139 view
140 }
141
142 fn take_frames(&mut self, cx: &mut Context<Self>) {
143 self.preview.take_frames(cx);
144 cx.notify();
145 }
146
147 fn load_devices(&mut self, demo: bool, cx: &mut Context<Self>) {
148 cx.spawn(async move |this, cx| {
149 let (cameras, audio_devices) = cx
150 .background_executor()
151 .spawn(async move {
152 let audio_devices = (!demo).then(|| list_devices(&shared_factory()));
153 (list_cameras(), audio_devices)
154 })
155 .await;
156 this.update(cx, |view, cx| {
157 view.cameras = camera_entries(&cameras);
158 if let Some(audio_devices) = audio_devices {
159 view.audio_devices = audio_devices;
160 }
161 cx.notify();
162 })
163 .ok();
164 })
165 .detach();
166 }
167
168 fn start_preview(&mut self) {
169 if !self.preview_blocked {
170 self.preview.start(&self.camera);
171 }
172 }
173
174 fn sync_preview_block(&mut self, cx: &mut Context<Self>) {
175 let blocked = camera_in_call(self.app.read(cx));
176 if blocked == self.preview_blocked {
177 return;
178 }
179 self.preview_blocked = blocked;
180 if blocked {
181 self.preview.stop(cx);
182 } else {
183 self.start_preview();
184 }
185 cx.notify();
186 }
187
188 fn select_camera(&mut self, camera: DeviceChoice, cx: &mut Context<Self>) {
189 self.camera = camera.clone();
190 self.app
191 .update(cx, |state, cx| state.select_call_camera(camera, cx));
192 self.start_preview();
193 cx.notify();
194 }
195
196 fn select_background(&mut self, pick: BackgroundPick, cx: &mut Context<Self>) {
197 self.background = pick.clone();
198 self.app
199 .update(cx, |state, cx| state.set_call_background(pick, cx));
200 self.apply_background(cx);
201 cx.notify();
202 }
203
204 fn apply_background(&self, cx: &App) {
205 let state = self.app.read(cx);
206 if let Some(choice) = state.call_backgrounds.choice_for(&self.background) {
207 self.preview.set_background(choice);
208 }
209 }
210
211 fn set_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) {
212 self.app
213 .update(cx, |state, cx| state.set_call_mic(settings, cx));
214 cx.notify();
215 }
216
217 fn set_effects(&mut self, effects: CameraEffects, cx: &mut Context<Self>) {
218 self.preview.set_effects(effects);
219 self.app
220 .update(cx, |state, cx| state.set_call_effects(effects, cx));
221 cx.notify();
222 }
223
224 fn preview_status(&self) -> String {
225 if self.preview_blocked {
226 return CAMERA_IN_USE.to_owned();
227 }
228 match self.preview.failure() {
229 Some(reason) => format!("Camera could not start: {reason}"),
230 None => self
231 .preview
232 .fps()
233 .map_or("Starting camera...".to_owned(), |fps| {
234 format!("{fps:.0} fps")
235 }),
236 }
237 }
238
239 fn audio_rows(&self, cx: &mut Context<Self>) -> Vec<AnyElement> {
240 let view = cx.entity();
241 let state = self.app.read(cx);
242 let (input, output, mic) = (
243 state.call_input.clone(),
244 state.call_output.clone(),
245 state.call_mic,
246 );
247 let device_choices = |entries: Vec<DeviceEntry>, current: &DeviceChoice, output: bool| {
248 entries
249 .into_iter()
250 .map(|entry| {
251 let (app, choice) = (self.app.clone(), entry.choice.clone());
252 Choice::new(entry.label, &entry.choice == current, move |cx| {
253 let choice = choice.clone();
254 app.update(cx, |state, cx| {
255 if output {
256 state.select_call_output(choice, cx)
257 } else {
258 state.select_call_input(choice, cx)
259 }
260 })
261 })
262 })
263 .collect::<Vec<_>>()
264 };
265 let (outputs, inputs) = (
266 self.audio_devices.output_entries(),
267 self.audio_devices.input_entries(),
268 );
269 let speaker_label = label_of(&outputs, &output, DEFAULT_DEVICE_LABEL);
270 let microphone_label = label_of(&inputs, &input, DEFAULT_DEVICE_LABEL);
271 let noise_choices = NoiseSuppression::ALL
272 .iter()
273 .map(|level| {
274 let (view, level) = (view.clone(), *level);
275 Choice::new(level.label(), level == mic.noise_suppression, move |cx| {
276 view.update(cx, |view, cx| {
277 view.set_mic(
278 MicSettings {
279 noise_suppression: level,
280 ..mic
281 },
282 cx,
283 )
284 })
285 })
286 })
287 .collect();
288 let music_view = view.clone();
289 let call_app = self.app.clone();
290 vec![
291 control_row(
292 "Speaker",
293 "",
294 select(
295 "settings-speaker",
296 speaker_label,
297 false,
298 device_choices(outputs, &output, true),
299 ),
300 )
301 .into_any_element(),
302 control_row(
303 "Microphone",
304 "",
305 select(
306 "settings-microphone",
307 microphone_label,
308 false,
309 device_choices(inputs, &input, false),
310 ),
311 )
312 .into_any_element(),
313 control_row(
314 "Noise suppression",
315 if mic.music_mode {
316 "Off while music mode is on"
317 } else {
318 "Echo, hum and background noise"
319 },
320 select(
321 "noise-suppression-select",
322 mic.noise_suppression.label(),
323 mic.music_mode,
324 noise_choices,
325 ),
326 )
327 .into_any_element(),
328 toggle_row(
329 "music-mode-row",
330 "Music mode",
331 "Keeps echo cancellation, turns off the rest",
332 theme::text_muted(),
333 mic.music_mode,
334 )
335 .on_click(move |_, _, cx| {
336 music_view.update(cx, |view, cx| {
337 view.set_mic(
338 MicSettings {
339 music_mode: !mic.music_mode,
340 ..mic
341 },
342 cx,
343 )
344 })
345 })
346 .into_any_element(),
347 control_row(
348 "Make a test call",
349 "Echo bot, checks your speaker and microphone",
350 text_button("settings-test-call", "Make a test call").on_click(move |_, _, cx| {
351 call_app.update(cx, |state, cx| state.start_test_call(cx))
352 }),
353 )
354 .into_any_element(),
355 ]
356 }
357
358 fn camera_block(&self, cx: &mut Context<Self>) -> Div {
359 let view = cx.entity();
360 let camera_label = label_of(&self.cameras, &self.camera, DEFAULT_CAMERA_LABEL);
361 let camera_choices = self
362 .cameras
363 .iter()
364 .map(|entry| {
365 let (view, choice) = (view.clone(), entry.choice.clone());
366 Choice::new(
367 entry.label.clone(),
368 entry.choice == self.camera,
369 move |cx| view.update(cx, |view, cx| view.select_camera(choice.clone(), cx)),
370 )
371 })
372 .collect();
373 let backgrounds = preview_backgrounds(&self.app.read(cx).call_backgrounds);
374 let background_label = backgrounds
375 .iter()
376 .find(|(pick, _)| *pick == self.background)
377 .map_or("None".to_owned(), |(_, label)| label.clone());
378 let background_choices = backgrounds
379 .into_iter()
380 .map(|(pick, label)| {
381 let view = view.clone();
382 let checked = pick == self.background;
383 Choice::new(label, checked, move |cx| {
384 view.update(cx, |view, cx| view.select_background(pick.clone(), cx))
385 })
386 })
387 .collect();
388 let image = self.preview.image(Instant::now());
389 v_flex()
390 .w_full()
391 .child(
392 row()
393 .items_start()
394 .flex_wrap()
395 .child(
396 div()
397 .w(px(PREVIEW_WIDTH))
398 .h(px(PREVIEW_HEIGHT))
399 .flex_none()
400 .flex()
401 .items_center()
402 .justify_center()
403 .overflow_hidden()
404 .rounded(px(PREVIEW_RADIUS))
405 .bg(theme::surface())
406 .children(image.map(|image| {
407 img(ImageSource::Render(image))
408 .size_full()
409 .object_fit(ObjectFit::Cover)
410 .rounded(px(PREVIEW_RADIUS))
411 })),
412 )
413 .child(
414 v_flex()
415 .gap(px(12.))
416 .child(device_label("Camera"))
417 .child(select("camera-select", camera_label, false, camera_choices))
418 .child(device_label("Background"))
419 .child(select(
420 "background-select",
421 background_label,
422 false,
423 background_choices,
424 )),
425 ),
426 )
427 .child(
428 div()
429 .px(px(super::rows::ROW_INSET))
430 .text_size(px(12.))
431 .text_color(theme::text_muted())
432 .child(self.preview_status()),
433 )
434 }
435
436 fn effect_rows(&self, cx: &mut Context<Self>) -> Vec<AnyElement> {
437 let effects = self.app.read(cx).call_effects;
438 let mut rows: Vec<AnyElement> = EFFECTS
439 .iter()
440 .map(|effect| {
441 let view = cx.entity();
442 let flip = effect.flip;
443 toggle_row(
444 effect.id,
445 effect.title,
446 "",
447 theme::text_muted(),
448 (effect.read)(&effects),
449 )
450 .on_click(move |_, _, cx| {
451 view.update(cx, |view, cx| {
452 let mut changed = view.app.read(cx).call_effects;
453 flip(&mut changed);
454 view.set_effects(changed, cx)
455 })
456 })
457 .into_any_element()
458 })
459 .collect();
460 if effects.soft_focus {
461 rows.push(self.strength_row(effects, cx).into_any_element());
462 }
463 rows
464 }
465
466 fn strength_row(&self, effects: CameraEffects, cx: &mut Context<Self>) -> Div {
467 let levels = SOFT_FOCUS_LEVELS.map(|(label, level)| {
468 let view = cx.entity();
469 text_button(label, label)
470 .when(effects.soft_focus_strength == level, |button| {
471 button.bg(theme::accent()).text_color(theme::on_accent())
472 })
473 .on_click(move |_, _, cx| {
474 view.update(cx, |view, cx| {
475 let changed = CameraEffects {
476 soft_focus_strength: level,
477 ..view.app.read(cx).call_effects
478 };
479 view.set_effects(changed, cx)
480 })
481 })
482 });
483 control_row(
484 "Soft focus strength",
485 "",
486 h_flex().gap(px(8.)).children(levels),
487 )
488 }
489}
490
491fn device_label(text: &'static str) -> Div {
492 div()
493 .text_size(px(12.))
494 .text_color(theme::text_muted())
495 .child(text)
496}
497
498impl Render for DevicesView {
499 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
500 let report_on = self.app.read(cx).call_report_enabled;
501 let report_app = self.app.clone();
502 v_flex()
503 .w_full()
504 .child(caption("AUDIO DEVICES"))
505 .children(self.audio_rows(cx))
506 .child(caption("CAMERA"))
507 .child(self.camera_block(cx))
508 .children(self.effect_rows(cx))
509 .child(caption("DIAGNOSTICS"))
510 .child(
511 toggle_row(
512 "call-report-row",
513 "Save a test report after each call",
514 "Pseudonymized, stays on this computer",
515 theme::text_muted(),
516 report_on,
517 )
518 .on_click(move |_, _, cx| {
519 report_app.update(cx, |state, cx| {
520 state.set_call_report_enabled(!report_on, cx)
521 })
522 }),
523 )
524 }
525}
crates/app/src/settings/dialog.rs added +305 −0
@@ -0,0 +1,305 @@
1 use app_ui_kit::settings_controls::PAGE_PADDING;
2 use gpui_kit::assets::IconName;
3 use gpui_kit::component::{h_flex, v_flex};
4 use gpui_kit::*;
5
6 use super::devices::DevicesView;
7 use super::mcp::McpView;
8 use super::nav::{NavLayout, label, render_nav};
9 use super::rows::ROW_INSET;
10 use super::{about, calls, chats, general, notifications};
11 use crate::agents::AgentsSettings;
12 use crate::app_state::AppState;
13 use crate::notify::NotificationCenter;
14 use crate::settings_section::SettingsSection;
15 use crate::theme::{self, ElevatedSurface as _};
16 use crate::views::widgets::icon;
17
18 const BACKDROP_OPACITY: f32 = 0.55;
19 const PANEL_RADIUS: f32 = 10.;
20 const CONTENT_MAX_WIDTH: f32 = 744.;
21 const CLOSE_SIZE: f32 = 32.;
22 const COMPACT_BELOW_WIDTH: f32 = 1100.;
23 const COMPACT_BELOW_HEIGHT: f32 = 720.;
24
25 pub enum SettingsDialogEvent {
26 Close,
27 }
28
29 #[derive(Debug, Clone, Copy, PartialEq)]
30 pub struct DialogMetrics {
31 pub inset: f32,
32 pub nav_width: f32,
33 pub padding: f32,
34 }
35
36 pub fn metrics(window_width: f32, window_height: f32) -> DialogMetrics {
37 if window_width < COMPACT_BELOW_WIDTH || window_height < COMPACT_BELOW_HEIGHT {
38 DialogMetrics {
39 inset: 24.,
40 nav_width: 216.,
41 padding: 18.,
42 }
43 } else {
44 DialogMetrics {
45 inset: 48.,
46 nav_width: 264.,
47 padding: 24.,
48 }
49 }
50 }
51
52 pub fn available(section: SettingsSection, agents_available: bool) -> SettingsSection {
53 if section == SettingsSection::Agents && !agents_available {
54 SettingsSection::General
55 } else {
56 section
57 }
58 }
59
60 pub struct SettingsDialog {
61 app: Entity<AppState>,
62 center: Entity<NotificationCenter>,
63 section: SettingsSection,
64 devices: Option<Entity<DevicesView>>,
65 mcp: Option<Entity<McpView>>,
66 agents: Option<Entity<AgentsSettings>>,
67 focus_handle: FocusHandle,
68 _subscriptions: [Subscription; 2],
69 }
70
71 impl EventEmitter<SettingsDialogEvent> for SettingsDialog {}
72
73 impl SettingsDialog {
74 pub fn new(
75 app: Entity<AppState>,
76 center: Entity<NotificationCenter>,
77 section: SettingsSection,
78 window: &mut Window,
79 cx: &mut Context<Self>,
80 ) -> Self {
81 let subscriptions = [
82 cx.observe(&center, |_, _, cx| cx.notify()),
83 cx.observe(&app, |_, _, cx| cx.notify()),
84 ];
85 let focus_handle = cx.focus_handle();
86 window.focus(&focus_handle, cx);
87 let mut dialog = SettingsDialog {
88 app,
89 center,
90 section,
91 devices: None,
92 mcp: None,
93 agents: None,
94 focus_handle,
95 _subscriptions: subscriptions,
96 };
97 dialog.show(section, window, cx);
98 dialog
99 }
100
101 pub fn show(&mut self, section: SettingsSection, window: &mut Window, cx: &mut Context<Self>) {
102 let section = available(section, crate::agents::runs_handle(cx).is_some());
103 self.section = section;
104 if section == SettingsSection::Devices {
105 if self.devices.is_none() {
106 let app = self.app.clone();
107 self.devices = Some(cx.new(|cx| DevicesView::new(app, cx)));
108 }
109 } else {
110 self.devices = None;
111 }
112 if section == SettingsSection::Mcp && self.mcp.is_none() {
113 let app = self.app.clone();
114 self.mcp = Some(cx.new(|cx| McpView::new(app, window, cx)));
115 }
116 if section == SettingsSection::Agents && self.agents.is_none() {
117 self.agents = crate::agents::runs_handle(cx)
118 .map(|runs| cx.new(|cx| AgentsSettings::new(runs, cx)));
119 }
120 cx.notify();
121 }
122
123 fn on_key_down(&mut self, event: &KeyDownEvent, _: &mut Window, cx: &mut Context<Self>) {
124 if event.keystroke.key == "escape" {
125 cx.emit(SettingsDialogEvent::Close);
126 cx.stop_propagation();
127 }
128 }
129
130 fn content(&self, cx: &mut Context<Self>) -> AnyElement {
131 match self.section {
132 SettingsSection::General => {
133 general::render(&self.center, &self.app, cx).into_any_element()
134 }
135 SettingsSection::Notifications => {
136 notifications::render(&self.center, cx).into_any_element()
137 }
138 SettingsSection::Chats => chats::render(&self.app, cx).into_any_element(),
139 SettingsSection::Calls => calls::render(&self.center, cx).into_any_element(),
140 SettingsSection::Devices => self
141 .devices
142 .clone()
143 .map_or_else(|| div().into_any_element(), |view| view.into_any_element()),
144 SettingsSection::Agents => self
145 .agents
146 .clone()
147 .map_or_else(|| div().into_any_element(), |view| view.into_any_element()),
148 SettingsSection::Mcp => self
149 .mcp
150 .clone()
151 .map_or_else(|| div().into_any_element(), |view| view.into_any_element()),
152 SettingsSection::About => about::render().into_any_element(),
153 }
154 }
155
156 fn header(&self, metrics: DialogMetrics, cx: &mut Context<Self>) -> Div {
157 h_flex()
158 .debug_selector(|| "settings/main/header".into())
159 .w_full()
160 .flex_none()
161 .items_center()
162 .pt(px(metrics.padding))
163 .pr(px(metrics.padding))
164 .pb(px(metrics.padding / 2.))
165 .pl(px(metrics.padding + ROW_INSET))
166 .child(
167 div()
168 .flex_1()
169 .min_w_0()
170 .truncate()
171 .text_size(px(20.))
172 .line_height(px(28.))
173 .font_weight(FontWeight::SEMIBOLD)
174 .text_color(theme::text())
175 .child(label(self.section)),
176 )
177 .child(
178 div()
179 .id("settings-close")
180 .size(px(CLOSE_SIZE))
181 .flex_none()
182 .flex()
183 .items_center()
184 .justify_center()
185 .rounded(px(6.))
186 .cursor_pointer()
187 .hover(|button| button.bg(theme::popup_hover()))
188 .on_click(cx.listener(|_, _, _, cx| cx.emit(SettingsDialogEvent::Close)))
189 .child(icon(IconName::X, 16., theme::text_muted())),
190 )
191 }
192 }
193
194 impl Render for SettingsDialog {
195 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
196 let viewport = window.viewport_size();
197 let metrics = metrics(f32::from(viewport.width), f32::from(viewport.height));
198 let dialog = cx.entity();
199 let nav = render_nav(
200 self.section,
201 crate::agents::runs_handle(cx).is_some(),
202 NavLayout {
203 width: metrics.nav_width,
204 padding_y: metrics.padding,
205 },
206 move |section, window, cx| {
207 dialog.update(cx, |dialog, cx| dialog.show(section, window, cx))
208 },
209 );
210 let body_inset = if self.section == SettingsSection::Agents {
211 metrics.padding + ROW_INSET - PAGE_PADDING
212 } else {
213 metrics.padding
214 };
215 let body = div()
216 .id(SharedString::from(format!(
217 "settings-body-{}",
218 label(self.section)
219 )))
220 .debug_selector(|| "settings/main/body".into())
221 .w_full()
222 .flex_1()
223 .min_h_0()
224 .overflow_y_scroll()
225 .px(px(body_inset.max(0.)))
226 .pb(px(metrics.padding))
227 .child(
228 div()
229 .w_full()
230 .max_w(px(CONTENT_MAX_WIDTH))
231 .child(self.content(cx)),
232 );
233 div()
234 .id("settings-layer")
235 .absolute()
236 .top_0()
237 .left_0()
238 .size_full()
239 .child(
240 div()
241 .id("settings-backdrop")
242 .absolute()
243 .top_0()
244 .left_0()
245 .size_full()
246 .bg(black().opacity(BACKDROP_OPACITY))
247 .occlude()
248 .on_click(cx.listener(|_, _, _, cx| cx.emit(SettingsDialogEvent::Close))),
249 )
250 .child(
251 h_flex()
252 .id("settings-dialog")
253 .debug_selector(|| "settings".into())
254 .track_focus(&self.focus_handle)
255 .on_key_down(cx.listener(Self::on_key_down))
256 .absolute()
257 .top(px(metrics.inset))
258 .left(px(metrics.inset))
259 .right(px(metrics.inset))
260 .bottom(px(metrics.inset))
261 .overflow_hidden()
262 .rounded(px(PANEL_RADIUS))
263 .dialog_surface()
264 .text_color(theme::text())
265 .occlude()
266 .child(nav)
267 .child(
268 v_flex()
269 .debug_selector(|| "settings/main".into())
270 .flex_1()
271 .min_w_0()
272 .h_full()
273 .child(self.header(metrics, cx))
274 .child(body),
275 ),
276 )
277 }
278 }
279
280 #[cfg(test)]
281 mod tests {
282 use super::{available, metrics};
283 use crate::settings_section::SettingsSection;
284
285 #[test]
286 fn small_windows_get_the_compact_inset() {
287 assert_eq!(metrics(1280., 800.).inset, 48.);
288 assert_eq!(metrics(1920., 1080.).nav_width, 264.);
289 assert_eq!(metrics(960., 640.).inset, 24.);
290 assert_eq!(metrics(1280., 640.).nav_width, 216.);
291 }
292
293 #[test]
294 fn agents_falls_back_to_general_without_agent_runs() {
295 assert_eq!(
296 available(SettingsSection::Agents, false),
297 SettingsSection::General
298 );
299 assert_eq!(
300 available(SettingsSection::Agents, true),
301 SettingsSection::Agents
302 );
303 assert_eq!(available(SettingsSection::Mcp, false), SettingsSection::Mcp);
304 }
305 }
@@ -0,0 +1,305 @@
1use app_ui_kit::settings_controls::PAGE_PADDING;
2use gpui_kit::assets::IconName;
3use gpui_kit::component::{h_flex, v_flex};
4use gpui_kit::*;
5
6use super::devices::DevicesView;
7use super::mcp::McpView;
8use super::nav::{NavLayout, label, render_nav};
9use super::rows::ROW_INSET;
10use super::{about, calls, chats, general, notifications};
11use crate::agents::AgentsSettings;
12use crate::app_state::AppState;
13use crate::notify::NotificationCenter;
14use crate::settings_section::SettingsSection;
15use crate::theme::{self, ElevatedSurface as _};
16use crate::views::widgets::icon;
17
18const BACKDROP_OPACITY: f32 = 0.55;
19const PANEL_RADIUS: f32 = 10.;
20const CONTENT_MAX_WIDTH: f32 = 744.;
21const CLOSE_SIZE: f32 = 32.;
22const COMPACT_BELOW_WIDTH: f32 = 1100.;
23const COMPACT_BELOW_HEIGHT: f32 = 720.;
24
25pub enum SettingsDialogEvent {
26 Close,
27}
28
29#[derive(Debug, Clone, Copy, PartialEq)]
30pub struct DialogMetrics {
31 pub inset: f32,
32 pub nav_width: f32,
33 pub padding: f32,
34}
35
36pub fn metrics(window_width: f32, window_height: f32) -> DialogMetrics {
37 if window_width < COMPACT_BELOW_WIDTH || window_height < COMPACT_BELOW_HEIGHT {
38 DialogMetrics {
39 inset: 24.,
40 nav_width: 216.,
41 padding: 18.,
42 }
43 } else {
44 DialogMetrics {
45 inset: 48.,
46 nav_width: 264.,
47 padding: 24.,
48 }
49 }
50}
51
52pub fn available(section: SettingsSection, agents_available: bool) -> SettingsSection {
53 if section == SettingsSection::Agents && !agents_available {
54 SettingsSection::General
55 } else {
56 section
57 }
58}
59
60pub struct SettingsDialog {
61 app: Entity<AppState>,
62 center: Entity<NotificationCenter>,
63 section: SettingsSection,
64 devices: Option<Entity<DevicesView>>,
65 mcp: Option<Entity<McpView>>,
66 agents: Option<Entity<AgentsSettings>>,
67 focus_handle: FocusHandle,
68 _subscriptions: [Subscription; 2],
69}
70
71impl EventEmitter<SettingsDialogEvent> for SettingsDialog {}
72
73impl SettingsDialog {
74 pub fn new(
75 app: Entity<AppState>,
76 center: Entity<NotificationCenter>,
77 section: SettingsSection,
78 window: &mut Window,
79 cx: &mut Context<Self>,
80 ) -> Self {
81 let subscriptions = [
82 cx.observe(&center, |_, _, cx| cx.notify()),
83 cx.observe(&app, |_, _, cx| cx.notify()),
84 ];
85 let focus_handle = cx.focus_handle();
86 window.focus(&focus_handle, cx);
87 let mut dialog = SettingsDialog {
88 app,
89 center,
90 section,
91 devices: None,
92 mcp: None,
93 agents: None,
94 focus_handle,
95 _subscriptions: subscriptions,
96 };
97 dialog.show(section, window, cx);
98 dialog
99 }
100
101 pub fn show(&mut self, section: SettingsSection, window: &mut Window, cx: &mut Context<Self>) {
102 let section = available(section, crate::agents::runs_handle(cx).is_some());
103 self.section = section;
104 if section == SettingsSection::Devices {
105 if self.devices.is_none() {
106 let app = self.app.clone();
107 self.devices = Some(cx.new(|cx| DevicesView::new(app, cx)));
108 }
109 } else {
110 self.devices = None;
111 }
112 if section == SettingsSection::Mcp && self.mcp.is_none() {
113 let app = self.app.clone();
114 self.mcp = Some(cx.new(|cx| McpView::new(app, window, cx)));
115 }
116 if section == SettingsSection::Agents && self.agents.is_none() {
117 self.agents = crate::agents::runs_handle(cx)
118 .map(|runs| cx.new(|cx| AgentsSettings::new(runs, cx)));
119 }
120 cx.notify();
121 }
122
123 fn on_key_down(&mut self, event: &KeyDownEvent, _: &mut Window, cx: &mut Context<Self>) {
124 if event.keystroke.key == "escape" {
125 cx.emit(SettingsDialogEvent::Close);
126 cx.stop_propagation();
127 }
128 }
129
130 fn content(&self, cx: &mut Context<Self>) -> AnyElement {
131 match self.section {
132 SettingsSection::General => {
133 general::render(&self.center, &self.app, cx).into_any_element()
134 }
135 SettingsSection::Notifications => {
136 notifications::render(&self.center, cx).into_any_element()
137 }
138 SettingsSection::Chats => chats::render(&self.app, cx).into_any_element(),
139 SettingsSection::Calls => calls::render(&self.center, cx).into_any_element(),
140 SettingsSection::Devices => self
141 .devices
142 .clone()
143 .map_or_else(|| div().into_any_element(), |view| view.into_any_element()),
144 SettingsSection::Agents => self
145 .agents
146 .clone()
147 .map_or_else(|| div().into_any_element(), |view| view.into_any_element()),
148 SettingsSection::Mcp => self
149 .mcp
150 .clone()
151 .map_or_else(|| div().into_any_element(), |view| view.into_any_element()),
152 SettingsSection::About => about::render().into_any_element(),
153 }
154 }
155
156 fn header(&self, metrics: DialogMetrics, cx: &mut Context<Self>) -> Div {
157 h_flex()
158 .debug_selector(|| "settings/main/header".into())
159 .w_full()
160 .flex_none()
161 .items_center()
162 .pt(px(metrics.padding))
163 .pr(px(metrics.padding))
164 .pb(px(metrics.padding / 2.))
165 .pl(px(metrics.padding + ROW_INSET))
166 .child(
167 div()
168 .flex_1()
169 .min_w_0()
170 .truncate()
171 .text_size(px(20.))
172 .line_height(px(28.))
173 .font_weight(FontWeight::SEMIBOLD)
174 .text_color(theme::text())
175 .child(label(self.section)),
176 )
177 .child(
178 div()
179 .id("settings-close")
180 .size(px(CLOSE_SIZE))
181 .flex_none()
182 .flex()
183 .items_center()
184 .justify_center()
185 .rounded(px(6.))
186 .cursor_pointer()
187 .hover(|button| button.bg(theme::popup_hover()))
188 .on_click(cx.listener(|_, _, _, cx| cx.emit(SettingsDialogEvent::Close)))
189 .child(icon(IconName::X, 16., theme::text_muted())),
190 )
191 }
192}
193
194impl Render for SettingsDialog {
195 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
196 let viewport = window.viewport_size();
197 let metrics = metrics(f32::from(viewport.width), f32::from(viewport.height));
198 let dialog = cx.entity();
199 let nav = render_nav(
200 self.section,
201 crate::agents::runs_handle(cx).is_some(),
202 NavLayout {
203 width: metrics.nav_width,
204 padding_y: metrics.padding,
205 },
206 move |section, window, cx| {
207 dialog.update(cx, |dialog, cx| dialog.show(section, window, cx))
208 },
209 );
210 let body_inset = if self.section == SettingsSection::Agents {
211 metrics.padding + ROW_INSET - PAGE_PADDING
212 } else {
213 metrics.padding
214 };
215 let body = div()
216 .id(SharedString::from(format!(
217 "settings-body-{}",
218 label(self.section)
219 )))
220 .debug_selector(|| "settings/main/body".into())
221 .w_full()
222 .flex_1()
223 .min_h_0()
224 .overflow_y_scroll()
225 .px(px(body_inset.max(0.)))
226 .pb(px(metrics.padding))
227 .child(
228 div()
229 .w_full()
230 .max_w(px(CONTENT_MAX_WIDTH))
231 .child(self.content(cx)),
232 );
233 div()
234 .id("settings-layer")
235 .absolute()
236 .top_0()
237 .left_0()
238 .size_full()
239 .child(
240 div()
241 .id("settings-backdrop")
242 .absolute()
243 .top_0()
244 .left_0()
245 .size_full()
246 .bg(black().opacity(BACKDROP_OPACITY))
247 .occlude()
248 .on_click(cx.listener(|_, _, _, cx| cx.emit(SettingsDialogEvent::Close))),
249 )
250 .child(
251 h_flex()
252 .id("settings-dialog")
253 .debug_selector(|| "settings".into())
254 .track_focus(&self.focus_handle)
255 .on_key_down(cx.listener(Self::on_key_down))
256 .absolute()
257 .top(px(metrics.inset))
258 .left(px(metrics.inset))
259 .right(px(metrics.inset))
260 .bottom(px(metrics.inset))
261 .overflow_hidden()
262 .rounded(px(PANEL_RADIUS))
263 .dialog_surface()
264 .text_color(theme::text())
265 .occlude()
266 .child(nav)
267 .child(
268 v_flex()
269 .debug_selector(|| "settings/main".into())
270 .flex_1()
271 .min_w_0()
272 .h_full()
273 .child(self.header(metrics, cx))
274 .child(body),
275 ),
276 )
277 }
278}
279
280#[cfg(test)]
281mod tests {
282 use super::{available, metrics};
283 use crate::settings_section::SettingsSection;
284
285 #[test]
286 fn small_windows_get_the_compact_inset() {
287 assert_eq!(metrics(1280., 800.).inset, 48.);
288 assert_eq!(metrics(1920., 1080.).nav_width, 264.);
289 assert_eq!(metrics(960., 640.).inset, 24.);
290 assert_eq!(metrics(1280., 640.).nav_width, 216.);
291 }
292
293 #[test]
294 fn agents_falls_back_to_general_without_agent_runs() {
295 assert_eq!(
296 available(SettingsSection::Agents, false),
297 SettingsSection::General
298 );
299 assert_eq!(
300 available(SettingsSection::Agents, true),
301 SettingsSection::Agents
302 );
303 assert_eq!(available(SettingsSection::Mcp, false), SettingsSection::Mcp);
304 }
305}
crates/app/src/settings/general.rs added +194 −0
@@ -0,0 +1,194 @@
1 use gpui_kit::assets::IconName;
2 use gpui_kit::component::{
3 button::Button,
4 h_flex,
5 menu::{DropdownMenu as _, PopupMenuItem},
6 v_flex,
7 };
8 use gpui_kit::*;
9 use teams_core::TranslationBehavior;
10
11 use super::rows::{Choice, caption, control_row, select, toggle_row};
12 use crate::app_state::AppState;
13 use crate::notify::NotificationCenter;
14 use crate::theme;
15 use crate::views::widgets::icon;
16
17 const BEHAVIORS: [(&str, TranslationBehavior); 3] = [
18 ("Ask me before translating", TranslationBehavior::Ask),
19 ("Auto-translate all messages", TranslationBehavior::Auto),
20 ("Never translate", TranslationBehavior::Never),
21 ];
22 const CHIP_HEIGHT: f32 = 24.;
23 const LANGUAGE_MENU_HEIGHT: f32 = 320.;
24
25 pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &App) -> Div {
26 let close_to_tray = center.read(cx).settings().close_to_tray;
27 let toggle_center = center.clone();
28 v_flex()
29 .w_full()
30 .child(caption("SYSTEM"))
31 .child(
32 toggle_row(
33 "settings-close-to-tray",
34 "On close, keep the application running",
35 "The title bar X hides the window to the tray",
36 theme::text_muted(),
37 close_to_tray,
38 )
39 .on_click(move |_, _, cx| {
40 toggle_center.update(cx, |center, cx| {
41 center.update_settings(cx, |settings| {
42 settings.close_to_tray = !settings.close_to_tray
43 })
44 })
45 }),
46 )
47 .child(caption("TRANSLATION"))
48 .children(translation_rows(app, cx))
49 }
50
51 fn translation_rows(app: &Entity<AppState>, cx: &App) -> Vec<AnyElement> {
52 let state = app.read(cx);
53 if state.translation.settings.is_none() {
54 return vec![
55 control_row("Translation", "Translation settings not loaded yet", div())
56 .into_any_element(),
57 ];
58 }
59 let translation = &state.translation;
60 let target = translation.target();
61 let behavior = translation.behavior();
62 let targets = translation
63 .languages
64 .iter()
65 .map(|language| {
66 let (app, code) = (app.clone(), language.code.clone());
67 Choice::new(language.name.clone(), language.code == target, move |cx| {
68 app.update(cx, |state, cx| state.set_translation_target(&code, cx))
69 })
70 })
71 .collect();
72 let behaviors = BEHAVIORS
73 .into_iter()
74 .map(|(label, choice)| {
75 let app = app.clone();
76 Choice::new(label, behavior == choice, move |cx| {
77 app.update(cx, |state, cx| state.set_translation_behavior(choice, cx))
78 })
79 })
80 .collect();
81 let behavior_label = BEHAVIORS
82 .iter()
83 .find(|(_, choice)| *choice == behavior)
84 .map_or("", |(label, _)| label);
85 vec![
86 control_row(
87 "Translate messages into this language",
88 "Read from your Teams account",
89 select(
90 "settings-translation-target",
91 translation.language_name(&target),
92 false,
93 targets,
94 ),
95 )
96 .into_any_element(),
97 control_row(
98 "How to handle messages in other languages",
99 "",
100 select(
101 "settings-translation-behavior",
102 behavior_label,
103 false,
104 behaviors,
105 ),
106 )
107 .into_any_element(),
108 control_row(
109 "Never translate messages in these languages",
110 "",
111 never_chips(app, &target, cx),
112 )
113 .into_any_element(),
114 ]
115 }
116
117 fn never_chips(app: &Entity<AppState>, target: &str, cx: &App) -> Div {
118 let translation = &app.read(cx).translation;
119 let never: Vec<String> = translation
120 .display_codes()
121 .into_iter()
122 .filter(|code| code != target)
123 .collect();
124 let chips = never.iter().map(|code| {
125 let (remove_app, remove_code) = (app.clone(), code.clone());
126 h_flex()
127 .h(px(CHIP_HEIGHT))
128 .pl(px(8.))
129 .gap(px(4.))
130 .items_center()
131 .rounded(px(6.))
132 .bg(theme::surface_raised())
133 .text_size(px(12.))
134 .text_color(theme::text_strong())
135 .child(translation.language_name(code))
136 .child(
137 div()
138 .id(SharedString::from(format!("settings-never-remove-{code}")))
139 .w(px(16.))
140 .h_full()
141 .flex()
142 .items_center()
143 .justify_center()
144 .cursor_pointer()
145 .child(icon(IconName::X, 10., theme::text_faint()))
146 .on_click(move |_, _, cx| {
147 remove_app.update(cx, |state, cx| {
148 state.allow_translating_language(&remove_code, cx)
149 })
150 }),
151 )
152 });
153 let addable = translation
154 .languages
155 .iter()
156 .filter(|language| language.code != target && !never.contains(&language.code))
157 .map(|language| {
158 let (app, code) = (app.clone(), language.code.clone());
159 Choice::new(language.name.clone(), false, move |cx| {
160 app.update(cx, |state, cx| state.never_translate_language(&code, cx))
161 })
162 })
163 .collect();
164 h_flex()
165 .flex_wrap()
166 .justify_end()
167 .gap(px(6.))
168 .items_center()
169 .children(chips)
170 .child(add_language_button(addable))
171 }
172
173 fn add_language_button(choices: Vec<Choice>) -> impl IntoElement {
174 Button::new("settings-never-add")
175 .outline()
176 .h(px(CHIP_HEIGHT))
177 .px(px(8.))
178 .rounded(px(6.))
179 .text_size(px(12.))
180 .text_color(theme::accent_text())
181 .label("+ Add language")
182 .dropdown_menu(move |menu, _, _| {
183 choices.iter().fold(
184 menu.max_h(px(LANGUAGE_MENU_HEIGHT)).scrollable(true),
185 |menu, choice| {
186 let choose = choice.choose.clone();
187 menu.item(
188 PopupMenuItem::new(choice.label.clone())
189 .on_click(move |_, _, cx| choose(cx)),
190 )
191 },
192 )
193 })
194 }
@@ -0,0 +1,194 @@
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{
3 button::Button,
4 h_flex,
5 menu::{DropdownMenu as _, PopupMenuItem},
6 v_flex,
7};
8use gpui_kit::*;
9use teams_core::TranslationBehavior;
10
11use super::rows::{Choice, caption, control_row, select, toggle_row};
12use crate::app_state::AppState;
13use crate::notify::NotificationCenter;
14use crate::theme;
15use crate::views::widgets::icon;
16
17const BEHAVIORS: [(&str, TranslationBehavior); 3] = [
18 ("Ask me before translating", TranslationBehavior::Ask),
19 ("Auto-translate all messages", TranslationBehavior::Auto),
20 ("Never translate", TranslationBehavior::Never),
21];
22const CHIP_HEIGHT: f32 = 24.;
23const LANGUAGE_MENU_HEIGHT: f32 = 320.;
24
25pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &App) -> Div {
26 let close_to_tray = center.read(cx).settings().close_to_tray;
27 let toggle_center = center.clone();
28 v_flex()
29 .w_full()
30 .child(caption("SYSTEM"))
31 .child(
32 toggle_row(
33 "settings-close-to-tray",
34 "On close, keep the application running",
35 "The title bar X hides the window to the tray",
36 theme::text_muted(),
37 close_to_tray,
38 )
39 .on_click(move |_, _, cx| {
40 toggle_center.update(cx, |center, cx| {
41 center.update_settings(cx, |settings| {
42 settings.close_to_tray = !settings.close_to_tray
43 })
44 })
45 }),
46 )
47 .child(caption("TRANSLATION"))
48 .children(translation_rows(app, cx))
49}
50
51fn translation_rows(app: &Entity<AppState>, cx: &App) -> Vec<AnyElement> {
52 let state = app.read(cx);
53 if state.translation.settings.is_none() {
54 return vec![
55 control_row("Translation", "Translation settings not loaded yet", div())
56 .into_any_element(),
57 ];
58 }
59 let translation = &state.translation;
60 let target = translation.target();
61 let behavior = translation.behavior();
62 let targets = translation
63 .languages
64 .iter()
65 .map(|language| {
66 let (app, code) = (app.clone(), language.code.clone());
67 Choice::new(language.name.clone(), language.code == target, move |cx| {
68 app.update(cx, |state, cx| state.set_translation_target(&code, cx))
69 })
70 })
71 .collect();
72 let behaviors = BEHAVIORS
73 .into_iter()
74 .map(|(label, choice)| {
75 let app = app.clone();
76 Choice::new(label, behavior == choice, move |cx| {
77 app.update(cx, |state, cx| state.set_translation_behavior(choice, cx))
78 })
79 })
80 .collect();
81 let behavior_label = BEHAVIORS
82 .iter()
83 .find(|(_, choice)| *choice == behavior)
84 .map_or("", |(label, _)| label);
85 vec![
86 control_row(
87 "Translate messages into this language",
88 "Read from your Teams account",
89 select(
90 "settings-translation-target",
91 translation.language_name(&target),
92 false,
93 targets,
94 ),
95 )
96 .into_any_element(),
97 control_row(
98 "How to handle messages in other languages",
99 "",
100 select(
101 "settings-translation-behavior",
102 behavior_label,
103 false,
104 behaviors,
105 ),
106 )
107 .into_any_element(),
108 control_row(
109 "Never translate messages in these languages",
110 "",
111 never_chips(app, &target, cx),
112 )
113 .into_any_element(),
114 ]
115}
116
117fn never_chips(app: &Entity<AppState>, target: &str, cx: &App) -> Div {
118 let translation = &app.read(cx).translation;
119 let never: Vec<String> = translation
120 .display_codes()
121 .into_iter()
122 .filter(|code| code != target)
123 .collect();
124 let chips = never.iter().map(|code| {
125 let (remove_app, remove_code) = (app.clone(), code.clone());
126 h_flex()
127 .h(px(CHIP_HEIGHT))
128 .pl(px(8.))
129 .gap(px(4.))
130 .items_center()
131 .rounded(px(6.))
132 .bg(theme::surface_raised())
133 .text_size(px(12.))
134 .text_color(theme::text_strong())
135 .child(translation.language_name(code))
136 .child(
137 div()
138 .id(SharedString::from(format!("settings-never-remove-{code}")))
139 .w(px(16.))
140 .h_full()
141 .flex()
142 .items_center()
143 .justify_center()
144 .cursor_pointer()
145 .child(icon(IconName::X, 10., theme::text_faint()))
146 .on_click(move |_, _, cx| {
147 remove_app.update(cx, |state, cx| {
148 state.allow_translating_language(&remove_code, cx)
149 })
150 }),
151 )
152 });
153 let addable = translation
154 .languages
155 .iter()
156 .filter(|language| language.code != target && !never.contains(&language.code))
157 .map(|language| {
158 let (app, code) = (app.clone(), language.code.clone());
159 Choice::new(language.name.clone(), false, move |cx| {
160 app.update(cx, |state, cx| state.never_translate_language(&code, cx))
161 })
162 })
163 .collect();
164 h_flex()
165 .flex_wrap()
166 .justify_end()
167 .gap(px(6.))
168 .items_center()
169 .children(chips)
170 .child(add_language_button(addable))
171}
172
173fn add_language_button(choices: Vec<Choice>) -> impl IntoElement {
174 Button::new("settings-never-add")
175 .outline()
176 .h(px(CHIP_HEIGHT))
177 .px(px(8.))
178 .rounded(px(6.))
179 .text_size(px(12.))
180 .text_color(theme::accent_text())
181 .label("+ Add language")
182 .dropdown_menu(move |menu, _, _| {
183 choices.iter().fold(
184 menu.max_h(px(LANGUAGE_MENU_HEIGHT)).scrollable(true),
185 |menu, choice| {
186 let choose = choice.choose.clone();
187 menu.item(
188 PopupMenuItem::new(choice.label.clone())
189 .on_click(move |_, _, cx| choose(cx)),
190 )
191 },
192 )
193 })
194}
crates/app/src/notify/settings_mcp.rs crates/app/src/settings/mcp.rs renamed +41 −163
@@ -12,7 +12,7 @@ use gpui_kit::*;
12 12 use mcp::install::{InstallReport, InstallState, Location, Target};
13 13 use mcp::{Access, AgentPolicy};
14 14
15 use super::settings_view::{control_row, switch, titled_with};
15 use super::rows::{ROW_INSET, caption, control_row, toggle_row};
16 16 use crate::agent_api::{self, ServerStatus};
17 17 use crate::app_state::AppState;
18 18 use crate::data::is_one_on_one;
@@ -23,7 +23,8 @@ use crate::views::widgets::icon;
23 23
24 24 const COPIED_SHOWN: Duration = Duration::from_millis(1500);
25 25 const PORT_WIDTH: f32 = 72.;
26 const FIELD_HEIGHT: f32 = 36.;
26 const FIELD_HEIGHT: f32 = 28.;
27 const FIELD_LABEL_WIDTH: f32 = 60.;
27 28 const SMALL_BUTTON_HEIGHT: f32 = 28.;
28 29 const PICKER_ROW_HEIGHT: f32 = 30.;
29 30 const PICKER_MAX_ROWS: usize = 6;
@@ -32,25 +33,6 @@ const TOKEN_TAIL: usize = 4;
32 33 const CHIP_MAX_WIDTH: f32 = 180.;
33 34 const WSL_WARNING: &str = "WSL agents cannot reach 127.0.0.1 on Windows. Add networkingMode=mirrored to .wslconfig and run wsl --shutdown.";
34 35
35 #[derive(Clone, Copy, PartialEq, Eq)]
36 enum McpTab {
37 Server,
38 Access,
39 Install,
40 }
41
42 impl McpTab {
43 const ALL: [McpTab; 3] = [McpTab::Server, McpTab::Access, McpTab::Install];
44
45 fn label(self) -> &'static str {
46 match self {
47 McpTab::Server => "Server",
48 McpTab::Access => "Access",
49 McpTab::Install => "Install",
50 }
51 }
52 }
53
54 36 #[derive(Clone, Copy, PartialEq, Eq)]
55 37 enum Scope {
56 38 Chats,
@@ -99,7 +81,6 @@ impl Scope {
99 81 enum Copied {
100 82 Url,
101 83 Token,
102 Manual,
103 84 }
104 85
105 86 #[derive(Clone, Copy, PartialEq, Eq)]
@@ -215,7 +196,6 @@ fn wsl_warning() -> Div {
215 196
216 197 pub struct McpView {
217 198 app: Entity<AppState>,
218 tab: McpTab,
219 199 picker: Option<Scope>,
220 200 port_input: Entity<InputState>,
221 201 port_invalid: bool,
@@ -249,7 +229,6 @@ impl McpView {
249 229 }
250 230 let mut view = McpView {
251 231 app,
252 tab: McpTab::Server,
253 232 picker: None,
254 233 port_input,
255 234 port_invalid: false,
@@ -262,6 +241,7 @@ impl McpView {
262 241 _subscriptions: subscriptions,
263 242 };
264 243 view.refresh_wsl(cx);
244 view.refresh_installs(cx);
265 245 view
266 246 }
267 247
@@ -368,20 +348,6 @@ impl McpView {
368 348 cx.notify();
369 349 }
370 350
371 fn select_tab(&mut self, tab: McpTab, cx: &mut Context<Self>) {
372 self.tab = tab;
373 self.picker = None;
374 match tab {
375 McpTab::Install => {
376 self.refresh_installs(cx);
377 self.refresh_wsl(cx);
378 }
379 McpTab::Server => self.refresh_wsl(cx),
380 McpTab::Access => {}
381 }
382 cx.notify();
383 }
384
385 351 fn copy(&mut self, target: Copied, text: String, cx: &mut Context<Self>) {
386 352 cx.write_to_clipboard(ClipboardItem::new_string(text));
387 353 self.copied = Some(target);
@@ -436,47 +402,16 @@ fn inert_button(id: impl Into<ElementId>, label: impl Into<SharedString>) -> Sta
436 402 .child(label.into())
437 403 }
438 404
439 fn caption(label: &'static str) -> Div {
440 div()
441 .px(px(20.))
442 .pt(px(16.))
443 .pb(px(4.))
444 .text_size(px(12.))
445 .font_weight(FontWeight::SEMIBOLD)
446 .text_color(theme::text_muted())
447 .child(label)
448 }
449
450 fn toggle_row(
451 id: &'static str,
452 title: &'static str,
453 detail: &'static str,
454 detail_color: Hsla,
455 on: bool,
456 ) -> Stateful<Div> {
457 h_flex()
458 .id(id)
459 .w_full()
460 .px(px(20.))
461 .py(px(10.))
462 .gap(px(12.))
463 .items_center()
464 .cursor_pointer()
465 .hover(|row| row.bg(theme::row_hover()))
466 .child(titled_with(title, detail, detail_color))
467 .child(switch(on))
468 }
469
470 405 fn note_box(content: impl IntoElement, margin_top: f32) -> Div {
471 406 h_flex()
472 .mx(px(20.))
407 .mx(px(ROW_INSET))
473 408 .mt(px(margin_top))
474 409 .mb(px(12.))
475 410 .px(px(12.))
476 411 .py(px(10.))
477 412 .gap(px(8.))
478 413 .rounded(px(8.))
479 .bg(theme::row_hover())
414 .bg(theme::surface_raised())
480 415 .text_size(px(12.))
481 416 .text_color(theme::text_muted())
482 417 .child(content)
@@ -511,51 +446,14 @@ fn chat_kind_label(state: &AppState, conversation_id: &str) -> Option<&'static s
511 446
512 447 impl Render for McpView {
513 448 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
514 let view = cx.entity();
515 let tabs = h_flex()
516 .mx(px(20.))
517 .mt(px(12.))
518 .mb(px(4.))
519 .p(px(2.))
520 .rounded(px(8.))
521 .bg(theme::surface())
522 .children(McpTab::ALL.map(|tab| {
523 let active = tab == self.tab;
524 let view = view.clone();
525 div()
526 .id(tab.label())
527 .flex_1()
528 .h(px(SMALL_BUTTON_HEIGHT))
529 .flex()
530 .items_center()
531 .justify_center()
532 .rounded(px(6.))
533 .cursor_pointer()
534 .text_size(px(12.))
535 .font_weight(FontWeight::SEMIBOLD)
536 .text_color(if active {
537 theme::text()
538 } else {
539 theme::text_muted()
540 })
541 .when(active, |tab| tab.bg(theme::surface_raised()))
542 .child(tab.label())
543 .on_click(move |_, _, cx| view.update(cx, |view, cx| view.select_tab(tab, cx)))
544 }));
545 let body = match self.tab {
546 McpTab::Server => self.server_tab(cx).into_any_element(),
547 McpTab::Access => self.access_tab(cx).into_any_element(),
548 McpTab::Install => self.install_tab(cx).into_any_element(),
549 };
550 v_flex().w_full().flex_1().min_h_0().child(tabs).child(
551 div()
552 .id("mcp-body")
553 .w_full()
554 .flex_1()
555 .min_h_0()
556 .overflow_y_scroll()
557 .child(body),
558 )
449 v_flex()
450 .w_full()
451 .child(caption("SERVER"))
452 .child(self.server_tab(cx))
453 .child(caption("ACCESS"))
454 .child(self.access_tab(cx))
455 .child(caption("INSTALL"))
456 .child(self.install_tab(cx))
559 457 }
560 458 }
561 459
@@ -567,39 +465,36 @@ impl McpView {
567 465 buttons: Vec<AnyElement>,
568 466 cx: &App,
569 467 ) -> Div {
570 v_flex()
468 h_flex()
571 469 .w_full()
572 .px(px(20.))
573 .pb(px(8.))
574 .gap(px(4.))
470 .px(px(ROW_INSET))
471 .py(px(6.))
472 .gap(px(8.))
473 .items_center()
575 474 .child(
576 475 div()
577 .text_size(px(11.))
476 .w(px(FIELD_LABEL_WIDTH))
477 .flex_none()
478 .text_size(px(12.))
578 479 .text_color(theme::text_faint())
579 480 .child(label),
580 481 )
581 482 .child(
582 h_flex()
583 .w_full()
584 .gap(px(8.))
483 div()
484 .flex_1()
485 .min_w_0()
486 .h(px(FIELD_HEIGHT))
487 .px(px(10.))
488 .flex()
585 489 .items_center()
586 .child(
587 div()
588 .flex_1()
589 .min_w_0()
590 .h(px(FIELD_HEIGHT))
591 .px(px(12.))
592 .flex()
593 .items_center()
594 .rounded(px(8.))
595 .bg(theme::surface())
596 .font_family(cx.theme().mono_font_family.clone())
597 .text_size(px(12.))
598 .text_color(theme::text_soft())
599 .child(div().truncate().child(value)),
600 )
601 .children(buttons),
490 .rounded(px(7.))
491 .bg(theme::surface_raised())
492 .font_family(cx.theme().mono_font_family.clone())
493 .text_size(px(12.))
494 .text_color(theme::text_soft())
495 .child(div().truncate().child(value)),
602 496 )
497 .children(buttons)
603 498 }
604 499
605 500 fn copy_button(
@@ -692,7 +587,7 @@ impl McpView {
692 587 .when(self.port_invalid, |tab| {
693 588 tab.child(
694 589 div()
695 .px(px(20.))
590 .px(px(ROW_INSET))
696 591 .pb(px(4.))
697 592 .text_size(px(12.))
698 593 .text_color(theme::red_soft())
@@ -702,7 +597,6 @@ impl McpView {
702 597 .when(running && self.wsl_unreachable, |tab| {
703 598 tab.child(wsl_warning())
704 599 })
705 .child(caption("CONNECTION"))
706 600 .child(self.field_row(
707 601 "URL",
708 602 url.clone(),
@@ -849,7 +743,7 @@ impl McpView {
849 743 .w_full()
850 744 .flex_wrap()
851 745 .gap(px(6.))
852 .px(px(20.))
746 .px(px(ROW_INSET))
853 747 .pb(px(8.))
854 748 .children(chips)
855 749 .child(add),
@@ -934,7 +828,7 @@ impl McpView {
934 828 })
935 829 .collect();
936 830 v_flex()
937 .mx(px(20.))
831 .mx(px(ROW_INSET))
938 832 .mb(px(8.))
939 833 .p(px(6.))
940 834 .gap(px(4.))
@@ -1043,7 +937,7 @@ impl McpView {
1043 937 .child(
1044 938 h_flex()
1045 939 .w_full()
1046 .px(px(20.))
940 .px(px(ROW_INSET))
1047 941 .py(px(8.))
1048 942 .gap(px(12.))
1049 943 .items_center()
@@ -1077,7 +971,7 @@ impl McpView {
1077 971 )
1078 972 .children(self.install_errors.get(&target).map(|message| {
1079 973 div()
1080 .px(px(20.))
974 .px(px(ROW_INSET))
1081 975 .pb(px(4.))
1082 976 .pl(px(60.))
1083 977 .text_size(px(12.))
@@ -1087,27 +981,11 @@ impl McpView {
1087 981 }
1088 982
1089 983 fn install_tab(&self, cx: &mut Context<Self>) -> Div {
1090 let url = agent_api::endpoint_url(agent_api::policy(cx).port);
1091 let running = agent_api::handle(cx)
1092 .is_some_and(|api| matches!(api.read(cx).status(), ServerStatus::Running(_)));
1093 984 let rows: Vec<Div> = Target::ALL
1094 985 .into_iter()
1095 986 .enumerate()
1096 987 .map(|(index, target)| self.install_row(index, target, cx))
1097 988 .collect();
1098 v_flex()
1099 .w_full()
1100 .pt(px(8.))
1101 .children(rows)
1102 .child(caption("MANUAL"))
1103 .child(self.field_row(
1104 "URL",
1105 url.clone(),
1106 vec![self.copy_button("mcp-manual-copy", Copied::Manual, url, cx)],
1107 cx,
1108 ))
1109 .when(running && self.wsl_unreachable, |tab| {
1110 tab.child(wsl_warning())
1111 })
989 v_flex().w_full().children(rows)
1112 990 }
1113 991 }
@@ -12,7 +12,7 @@ use gpui_kit::*;
12use mcp::install::{InstallReport, InstallState, Location, Target};
12use mcp::install::{InstallReport, InstallState, Location, Target};
13use mcp::{Access, AgentPolicy};
13use mcp::{Access, AgentPolicy};
14
14
15use super::settings_view::{control_row, switch, titled_with};
15use super::rows::{ROW_INSET, caption, control_row, toggle_row};
16use crate::agent_api::{self, ServerStatus};
16use crate::agent_api::{self, ServerStatus};
17use crate::app_state::AppState;
17use crate::app_state::AppState;
18use crate::data::is_one_on_one;
18use crate::data::is_one_on_one;
@@ -23,7 +23,8 @@ use crate::views::widgets::icon;
23
23
24const COPIED_SHOWN: Duration = Duration::from_millis(1500);
24const COPIED_SHOWN: Duration = Duration::from_millis(1500);
25const PORT_WIDTH: f32 = 72.;
25const PORT_WIDTH: f32 = 72.;
26const FIELD_HEIGHT: f32 = 36.;
26const FIELD_HEIGHT: f32 = 28.;
27const FIELD_LABEL_WIDTH: f32 = 60.;
27const SMALL_BUTTON_HEIGHT: f32 = 28.;
28const SMALL_BUTTON_HEIGHT: f32 = 28.;
28const PICKER_ROW_HEIGHT: f32 = 30.;
29const PICKER_ROW_HEIGHT: f32 = 30.;
29const PICKER_MAX_ROWS: usize = 6;
30const PICKER_MAX_ROWS: usize = 6;
@@ -32,25 +33,6 @@ const TOKEN_TAIL: usize = 4;
32const CHIP_MAX_WIDTH: f32 = 180.;
33const CHIP_MAX_WIDTH: f32 = 180.;
33const WSL_WARNING: &str = "WSL agents cannot reach 127.0.0.1 on Windows. Add networkingMode=mirrored to .wslconfig and run wsl --shutdown.";
34const WSL_WARNING: &str = "WSL agents cannot reach 127.0.0.1 on Windows. Add networkingMode=mirrored to .wslconfig and run wsl --shutdown.";
34
35
35#[derive(Clone, Copy, PartialEq, Eq)]
36enum McpTab {
37 Server,
38 Access,
39 Install,
40}
41
42impl McpTab {
43 const ALL: [McpTab; 3] = [McpTab::Server, McpTab::Access, McpTab::Install];
44
45 fn label(self) -> &'static str {
46 match self {
47 McpTab::Server => "Server",
48 McpTab::Access => "Access",
49 McpTab::Install => "Install",
50 }
51 }
52}
53
54#[derive(Clone, Copy, PartialEq, Eq)]
36#[derive(Clone, Copy, PartialEq, Eq)]
55enum Scope {
37enum Scope {
56 Chats,
38 Chats,
@@ -99,7 +81,6 @@ impl Scope {
99enum Copied {
81enum Copied {
100 Url,
82 Url,
101 Token,
83 Token,
102 Manual,
103}
84}
104
85
105#[derive(Clone, Copy, PartialEq, Eq)]
86#[derive(Clone, Copy, PartialEq, Eq)]
@@ -215,7 +196,6 @@ fn wsl_warning() -> Div {
215
196
216pub struct McpView {
197pub struct McpView {
217 app: Entity<AppState>,
198 app: Entity<AppState>,
218 tab: McpTab,
219 picker: Option<Scope>,
199 picker: Option<Scope>,
220 port_input: Entity<InputState>,
200 port_input: Entity<InputState>,
221 port_invalid: bool,
201 port_invalid: bool,
@@ -249,7 +229,6 @@ impl McpView {
249 }
229 }
250 let mut view = McpView {
230 let mut view = McpView {
251 app,
231 app,
252 tab: McpTab::Server,
253 picker: None,
232 picker: None,
254 port_input,
233 port_input,
255 port_invalid: false,
234 port_invalid: false,
@@ -262,6 +241,7 @@ impl McpView {
262 _subscriptions: subscriptions,
241 _subscriptions: subscriptions,
263 };
242 };
264 view.refresh_wsl(cx);
243 view.refresh_wsl(cx);
244 view.refresh_installs(cx);
265 view
245 view
266 }
246 }
267
247
@@ -368,20 +348,6 @@ impl McpView {
368 cx.notify();
348 cx.notify();
369 }
349 }
370
350
371 fn select_tab(&mut self, tab: McpTab, cx: &mut Context<Self>) {
372 self.tab = tab;
373 self.picker = None;
374 match tab {
375 McpTab::Install => {
376 self.refresh_installs(cx);
377 self.refresh_wsl(cx);
378 }
379 McpTab::Server => self.refresh_wsl(cx),
380 McpTab::Access => {}
381 }
382 cx.notify();
383 }
384
385 fn copy(&mut self, target: Copied, text: String, cx: &mut Context<Self>) {
351 fn copy(&mut self, target: Copied, text: String, cx: &mut Context<Self>) {
386 cx.write_to_clipboard(ClipboardItem::new_string(text));
352 cx.write_to_clipboard(ClipboardItem::new_string(text));
387 self.copied = Some(target);
353 self.copied = Some(target);
@@ -436,47 +402,16 @@ fn inert_button(id: impl Into<ElementId>, label: impl Into<SharedString>) -> Sta
436 .child(label.into())
402 .child(label.into())
437}
403}
438
404
439fn caption(label: &'static str) -> Div {
440 div()
441 .px(px(20.))
442 .pt(px(16.))
443 .pb(px(4.))
444 .text_size(px(12.))
445 .font_weight(FontWeight::SEMIBOLD)
446 .text_color(theme::text_muted())
447 .child(label)
448}
449
450fn toggle_row(
451 id: &'static str,
452 title: &'static str,
453 detail: &'static str,
454 detail_color: Hsla,
455 on: bool,
456) -> Stateful<Div> {
457 h_flex()
458 .id(id)
459 .w_full()
460 .px(px(20.))
461 .py(px(10.))
462 .gap(px(12.))
463 .items_center()
464 .cursor_pointer()
465 .hover(|row| row.bg(theme::row_hover()))
466 .child(titled_with(title, detail, detail_color))
467 .child(switch(on))
468}
469
470fn note_box(content: impl IntoElement, margin_top: f32) -> Div {
405fn note_box(content: impl IntoElement, margin_top: f32) -> Div {
471 h_flex()
406 h_flex()
472 .mx(px(20.))
407 .mx(px(ROW_INSET))
473 .mt(px(margin_top))
408 .mt(px(margin_top))
474 .mb(px(12.))
409 .mb(px(12.))
475 .px(px(12.))
410 .px(px(12.))
476 .py(px(10.))
411 .py(px(10.))
477 .gap(px(8.))
412 .gap(px(8.))
478 .rounded(px(8.))
413 .rounded(px(8.))
479 .bg(theme::row_hover())
414 .bg(theme::surface_raised())
480 .text_size(px(12.))
415 .text_size(px(12.))
481 .text_color(theme::text_muted())
416 .text_color(theme::text_muted())
482 .child(content)
417 .child(content)
@@ -511,51 +446,14 @@ fn chat_kind_label(state: &AppState, conversation_id: &str) -> Option<&'static s
511
446
512impl Render for McpView {
447impl Render for McpView {
513 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
448 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
514 let view = cx.entity();
449 v_flex()
515 let tabs = h_flex()
450 .w_full()
516 .mx(px(20.))
451 .child(caption("SERVER"))
517 .mt(px(12.))
452 .child(self.server_tab(cx))
518 .mb(px(4.))
453 .child(caption("ACCESS"))
519 .p(px(2.))
454 .child(self.access_tab(cx))
520 .rounded(px(8.))
455 .child(caption("INSTALL"))
521 .bg(theme::surface())
456 .child(self.install_tab(cx))
522 .children(McpTab::ALL.map(|tab| {
523 let active = tab == self.tab;
524 let view = view.clone();
525 div()
526 .id(tab.label())
527 .flex_1()
528 .h(px(SMALL_BUTTON_HEIGHT))
529 .flex()
530 .items_center()
531 .justify_center()
532 .rounded(px(6.))
533 .cursor_pointer()
534 .text_size(px(12.))
535 .font_weight(FontWeight::SEMIBOLD)
536 .text_color(if active {
537 theme::text()
538 } else {
539 theme::text_muted()
540 })
541 .when(active, |tab| tab.bg(theme::surface_raised()))
542 .child(tab.label())
543 .on_click(move |_, _, cx| view.update(cx, |view, cx| view.select_tab(tab, cx)))
544 }));
545 let body = match self.tab {
546 McpTab::Server => self.server_tab(cx).into_any_element(),
547 McpTab::Access => self.access_tab(cx).into_any_element(),
548 McpTab::Install => self.install_tab(cx).into_any_element(),
549 };
550 v_flex().w_full().flex_1().min_h_0().child(tabs).child(
551 div()
552 .id("mcp-body")
553 .w_full()
554 .flex_1()
555 .min_h_0()
556 .overflow_y_scroll()
557 .child(body),
558 )
559 }
457 }
560}
458}
561
459
@@ -567,39 +465,36 @@ impl McpView {
567 buttons: Vec<AnyElement>,
465 buttons: Vec<AnyElement>,
568 cx: &App,
466 cx: &App,
569 ) -> Div {
467 ) -> Div {
570 v_flex()
468 h_flex()
571 .w_full()
469 .w_full()
572 .px(px(20.))
470 .px(px(ROW_INSET))
573 .pb(px(8.))
471 .py(px(6.))
574 .gap(px(4.))
472 .gap(px(8.))
473 .items_center()
575 .child(
474 .child(
576 div()
475 div()
577 .text_size(px(11.))
476 .w(px(FIELD_LABEL_WIDTH))
477 .flex_none()
478 .text_size(px(12.))
578 .text_color(theme::text_faint())
479 .text_color(theme::text_faint())
579 .child(label),
480 .child(label),
580 )
481 )
581 .child(
482 .child(
582 h_flex()
483 div()
583 .w_full()
484 .flex_1()
584 .gap(px(8.))
485 .min_w_0()
486 .h(px(FIELD_HEIGHT))
487 .px(px(10.))
488 .flex()
585 .items_center()
489 .items_center()
586 .child(
490 .rounded(px(7.))
587 div()
491 .bg(theme::surface_raised())
588 .flex_1()
492 .font_family(cx.theme().mono_font_family.clone())
589 .min_w_0()
493 .text_size(px(12.))
590 .h(px(FIELD_HEIGHT))
494 .text_color(theme::text_soft())
591 .px(px(12.))
495 .child(div().truncate().child(value)),
592 .flex()
593 .items_center()
594 .rounded(px(8.))
595 .bg(theme::surface())
596 .font_family(cx.theme().mono_font_family.clone())
597 .text_size(px(12.))
598 .text_color(theme::text_soft())
599 .child(div().truncate().child(value)),
600 )
601 .children(buttons),
602 )
496 )
497 .children(buttons)
603 }
498 }
604
499
605 fn copy_button(
500 fn copy_button(
@@ -692,7 +587,7 @@ impl McpView {
692 .when(self.port_invalid, |tab| {
587 .when(self.port_invalid, |tab| {
693 tab.child(
588 tab.child(
694 div()
589 div()
695 .px(px(20.))
590 .px(px(ROW_INSET))
696 .pb(px(4.))
591 .pb(px(4.))
697 .text_size(px(12.))
592 .text_size(px(12.))
698 .text_color(theme::red_soft())
593 .text_color(theme::red_soft())
@@ -702,7 +597,6 @@ impl McpView {
702 .when(running && self.wsl_unreachable, |tab| {
597 .when(running && self.wsl_unreachable, |tab| {
703 tab.child(wsl_warning())
598 tab.child(wsl_warning())
704 })
599 })
705 .child(caption("CONNECTION"))
706 .child(self.field_row(
600 .child(self.field_row(
707 "URL",
601 "URL",
708 url.clone(),
602 url.clone(),
@@ -849,7 +743,7 @@ impl McpView {
849 .w_full()
743 .w_full()
850 .flex_wrap()
744 .flex_wrap()
851 .gap(px(6.))
745 .gap(px(6.))
852 .px(px(20.))
746 .px(px(ROW_INSET))
853 .pb(px(8.))
747 .pb(px(8.))
854 .children(chips)
748 .children(chips)
855 .child(add),
749 .child(add),
@@ -934,7 +828,7 @@ impl McpView {
934 })
828 })
935 .collect();
829 .collect();
936 v_flex()
830 v_flex()
937 .mx(px(20.))
831 .mx(px(ROW_INSET))
938 .mb(px(8.))
832 .mb(px(8.))
939 .p(px(6.))
833 .p(px(6.))
940 .gap(px(4.))
834 .gap(px(4.))
@@ -1043,7 +937,7 @@ impl McpView {
1043 .child(
937 .child(
1044 h_flex()
938 h_flex()
1045 .w_full()
939 .w_full()
1046 .px(px(20.))
940 .px(px(ROW_INSET))
1047 .py(px(8.))
941 .py(px(8.))
1048 .gap(px(12.))
942 .gap(px(12.))
1049 .items_center()
943 .items_center()
@@ -1077,7 +971,7 @@ impl McpView {
1077 )
971 )
1078 .children(self.install_errors.get(&target).map(|message| {
972 .children(self.install_errors.get(&target).map(|message| {
1079 div()
973 div()
1080 .px(px(20.))
974 .px(px(ROW_INSET))
1081 .pb(px(4.))
975 .pb(px(4.))
1082 .pl(px(60.))
976 .pl(px(60.))
1083 .text_size(px(12.))
977 .text_size(px(12.))
@@ -1087,27 +981,11 @@ impl McpView {
1087 }
981 }
1088
982
1089 fn install_tab(&self, cx: &mut Context<Self>) -> Div {
983 fn install_tab(&self, cx: &mut Context<Self>) -> Div {
1090 let url = agent_api::endpoint_url(agent_api::policy(cx).port);
1091 let running = agent_api::handle(cx)
1092 .is_some_and(|api| matches!(api.read(cx).status(), ServerStatus::Running(_)));
1093 let rows: Vec<Div> = Target::ALL
984 let rows: Vec<Div> = Target::ALL
1094 .into_iter()
985 .into_iter()
1095 .enumerate()
986 .enumerate()
1096 .map(|(index, target)| self.install_row(index, target, cx))
987 .map(|(index, target)| self.install_row(index, target, cx))
1097 .collect();
988 .collect();
1098 v_flex()
989 v_flex().w_full().children(rows)
1099 .w_full()
1100 .pt(px(8.))
1101 .children(rows)
1102 .child(caption("MANUAL"))
1103 .child(self.field_row(
1104 "URL",
1105 url.clone(),
1106 vec![self.copy_button("mcp-manual-copy", Copied::Manual, url, cx)],
1107 cx,
1108 ))
1109 .when(running && self.wsl_unreachable, |tab| {
1110 tab.child(wsl_warning())
1111 })
1112 }
990 }
1113}
991}
crates/app/src/settings/mod.rs added +15 −0
@@ -0,0 +1,15 @@
1 mod about;
2 mod calls;
3 mod chats;
4 mod devices;
5 mod dialog;
6 mod general;
7 mod mcp;
8 mod nav;
9 mod notifications;
10 mod rows;
11
12 pub use dialog::{SettingsDialog, SettingsDialogEvent};
13 #[cfg(test)]
14 pub use dialog::metrics;
15 pub(crate) use rows::switch;
@@ -0,0 +1,15 @@
1mod about;
2mod calls;
3mod chats;
4mod devices;
5mod dialog;
6mod general;
7mod mcp;
8mod nav;
9mod notifications;
10mod rows;
11
12pub use dialog::{SettingsDialog, SettingsDialogEvent};
13#[cfg(test)]
14pub use dialog::metrics;
15pub(crate) use rows::switch;
crates/app/src/settings/nav.rs added +154 −0
@@ -0,0 +1,154 @@
1 use gpui_kit::assets::IconName;
2 use gpui_kit::component::{h_flex, v_flex};
3 use gpui_kit::prelude::FluentBuilder as _;
4 use gpui_kit::*;
5
6 use crate::settings_section::SettingsSection;
7 use crate::theme;
8 use crate::views::widgets::icon;
9
10 pub const TEAMS_GROUP: [SettingsSection; 5] = [
11 SettingsSection::General,
12 SettingsSection::Notifications,
13 SettingsSection::Chats,
14 SettingsSection::Calls,
15 SettingsSection::Devices,
16 ];
17 pub const RUSTY_GROUP: [SettingsSection; 2] = [SettingsSection::Agents, SettingsSection::Mcp];
18 const ITEM_HEIGHT: f32 = 34.;
19 const ITEM_GAP: f32 = 2.;
20 const ITEM_RADIUS: f32 = 6.;
21 const ITEM_ICON: f32 = 16.;
22 const NAV_PADDING_X: f32 = 12.;
23
24 pub fn label(section: SettingsSection) -> &'static str {
25 match section {
26 SettingsSection::General => "General",
27 SettingsSection::Notifications => "Notifications and activity",
28 SettingsSection::Chats => "Chats and channels",
29 SettingsSection::Calls => "Calls",
30 SettingsSection::Devices => "Devices",
31 SettingsSection::Agents => "Agents",
32 SettingsSection::Mcp => "MCP",
33 SettingsSection::About => "About",
34 }
35 }
36
37 fn icon_name(section: SettingsSection) -> IconName {
38 match section {
39 SettingsSection::General => IconName::SlidersHorizontal,
40 SettingsSection::Notifications => IconName::Bell,
41 SettingsSection::Chats => IconName::MessageSquare,
42 SettingsSection::Calls => IconName::Phone,
43 SettingsSection::Devices => IconName::Headphones,
44 SettingsSection::Agents => IconName::Bot,
45 SettingsSection::Mcp => IconName::Plug,
46 SettingsSection::About => IconName::Info,
47 }
48 }
49
50 fn element_id(section: SettingsSection) -> &'static str {
51 match section {
52 SettingsSection::General => "settings-nav-general",
53 SettingsSection::Notifications => "settings-nav-notifications",
54 SettingsSection::Chats => "settings-nav-chats",
55 SettingsSection::Calls => "settings-nav-calls",
56 SettingsSection::Devices => "settings-nav-devices",
57 SettingsSection::Agents => "settings-nav-agents",
58 SettingsSection::Mcp => "settings-nav-mcp",
59 SettingsSection::About => "settings-nav-about",
60 }
61 }
62
63 pub struct NavLayout {
64 pub width: f32,
65 pub padding_y: f32,
66 }
67
68 pub fn render_nav(
69 active: SettingsSection,
70 agents_available: bool,
71 layout: NavLayout,
72 on_select: impl Fn(SettingsSection, &mut Window, &mut App) + Clone + 'static,
73 ) -> Div {
74 let item = |section: SettingsSection| nav_item(section, section == active, on_select.clone());
75 let rusty: Vec<Stateful<Div>> = RUSTY_GROUP
76 .into_iter()
77 .filter(|section| agents_available || *section != SettingsSection::Agents)
78 .map(item)
79 .collect();
80 v_flex()
81 .debug_selector(|| "settings/nav".into())
82 .w(px(layout.width))
83 .h_full()
84 .flex_none()
85 .px(px(NAV_PADDING_X))
86 .py(px(layout.padding_y))
87 .gap(px(ITEM_GAP))
88 .bg(theme::surface_raised())
89 .child(
90 div()
91 .mx(px(12.))
92 .mb(px(18.))
93 .text_size(px(20.))
94 .line_height(px(26.))
95 .font_weight(FontWeight::SEMIBOLD)
96 .text_color(theme::text())
97 .child("Settings"),
98 )
99 .children(TEAMS_GROUP.map(item))
100 .child(
101 div()
102 .mt(px(10.))
103 .px(px(12.))
104 .pt(px(12.))
105 .pb(px(6.))
106 .border_t_1()
107 .border_color(theme::border_strong())
108 .text_size(px(12.))
109 .font_weight(FontWeight::SEMIBOLD)
110 .text_color(theme::text_muted())
111 .child("RUSTY TEAMS"),
112 )
113 .children(rusty)
114 .child(div().flex_1().min_h(px(0.)))
115 .child(item(SettingsSection::About))
116 }
117
118 fn nav_item(
119 section: SettingsSection,
120 active: bool,
121 on_select: impl Fn(SettingsSection, &mut Window, &mut App) + 'static,
122 ) -> Stateful<Div> {
123 h_flex()
124 .id(element_id(section))
125 .w_full()
126 .h(px(ITEM_HEIGHT))
127 .flex_none()
128 .px(px(12.))
129 .gap(px(12.))
130 .items_center()
131 .rounded(px(ITEM_RADIUS))
132 .cursor_pointer()
133 .text_size(px(14.))
134 .when(active, |item| {
135 item.bg(theme::popup_hover())
136 .font_weight(FontWeight::SEMIBOLD)
137 .text_color(theme::text())
138 })
139 .when(!active, |item| {
140 item.text_color(theme::text_strong())
141 .hover(|item| item.bg(theme::popup()))
142 })
143 .child(icon(
144 icon_name(section),
145 ITEM_ICON,
146 if active {
147 theme::accent_text()
148 } else {
149 theme::text_muted()
150 },
151 ))
152 .child(div().flex_1().min_w_0().truncate().child(label(section)))
153 .on_click(move |_, window, cx| on_select(section, window, cx))
154 }
@@ -0,0 +1,154 @@
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{h_flex, v_flex};
3use gpui_kit::prelude::FluentBuilder as _;
4use gpui_kit::*;
5
6use crate::settings_section::SettingsSection;
7use crate::theme;
8use crate::views::widgets::icon;
9
10pub const TEAMS_GROUP: [SettingsSection; 5] = [
11 SettingsSection::General,
12 SettingsSection::Notifications,
13 SettingsSection::Chats,
14 SettingsSection::Calls,
15 SettingsSection::Devices,
16];
17pub const RUSTY_GROUP: [SettingsSection; 2] = [SettingsSection::Agents, SettingsSection::Mcp];
18const ITEM_HEIGHT: f32 = 34.;
19const ITEM_GAP: f32 = 2.;
20const ITEM_RADIUS: f32 = 6.;
21const ITEM_ICON: f32 = 16.;
22const NAV_PADDING_X: f32 = 12.;
23
24pub fn label(section: SettingsSection) -> &'static str {
25 match section {
26 SettingsSection::General => "General",
27 SettingsSection::Notifications => "Notifications and activity",
28 SettingsSection::Chats => "Chats and channels",
29 SettingsSection::Calls => "Calls",
30 SettingsSection::Devices => "Devices",
31 SettingsSection::Agents => "Agents",
32 SettingsSection::Mcp => "MCP",
33 SettingsSection::About => "About",
34 }
35}
36
37fn icon_name(section: SettingsSection) -> IconName {
38 match section {
39 SettingsSection::General => IconName::SlidersHorizontal,
40 SettingsSection::Notifications => IconName::Bell,
41 SettingsSection::Chats => IconName::MessageSquare,
42 SettingsSection::Calls => IconName::Phone,
43 SettingsSection::Devices => IconName::Headphones,
44 SettingsSection::Agents => IconName::Bot,
45 SettingsSection::Mcp => IconName::Plug,
46 SettingsSection::About => IconName::Info,
47 }
48}
49
50fn element_id(section: SettingsSection) -> &'static str {
51 match section {
52 SettingsSection::General => "settings-nav-general",
53 SettingsSection::Notifications => "settings-nav-notifications",
54 SettingsSection::Chats => "settings-nav-chats",
55 SettingsSection::Calls => "settings-nav-calls",
56 SettingsSection::Devices => "settings-nav-devices",
57 SettingsSection::Agents => "settings-nav-agents",
58 SettingsSection::Mcp => "settings-nav-mcp",
59 SettingsSection::About => "settings-nav-about",
60 }
61}
62
63pub struct NavLayout {
64 pub width: f32,
65 pub padding_y: f32,
66}
67
68pub fn render_nav(
69 active: SettingsSection,
70 agents_available: bool,
71 layout: NavLayout,
72 on_select: impl Fn(SettingsSection, &mut Window, &mut App) + Clone + 'static,
73) -> Div {
74 let item = |section: SettingsSection| nav_item(section, section == active, on_select.clone());
75 let rusty: Vec<Stateful<Div>> = RUSTY_GROUP
76 .into_iter()
77 .filter(|section| agents_available || *section != SettingsSection::Agents)
78 .map(item)
79 .collect();
80 v_flex()
81 .debug_selector(|| "settings/nav".into())
82 .w(px(layout.width))
83 .h_full()
84 .flex_none()
85 .px(px(NAV_PADDING_X))
86 .py(px(layout.padding_y))
87 .gap(px(ITEM_GAP))
88 .bg(theme::surface_raised())
89 .child(
90 div()
91 .mx(px(12.))
92 .mb(px(18.))
93 .text_size(px(20.))
94 .line_height(px(26.))
95 .font_weight(FontWeight::SEMIBOLD)
96 .text_color(theme::text())
97 .child("Settings"),
98 )
99 .children(TEAMS_GROUP.map(item))
100 .child(
101 div()
102 .mt(px(10.))
103 .px(px(12.))
104 .pt(px(12.))
105 .pb(px(6.))
106 .border_t_1()
107 .border_color(theme::border_strong())
108 .text_size(px(12.))
109 .font_weight(FontWeight::SEMIBOLD)
110 .text_color(theme::text_muted())
111 .child("RUSTY TEAMS"),
112 )
113 .children(rusty)
114 .child(div().flex_1().min_h(px(0.)))
115 .child(item(SettingsSection::About))
116}
117
118fn nav_item(
119 section: SettingsSection,
120 active: bool,
121 on_select: impl Fn(SettingsSection, &mut Window, &mut App) + 'static,
122) -> Stateful<Div> {
123 h_flex()
124 .id(element_id(section))
125 .w_full()
126 .h(px(ITEM_HEIGHT))
127 .flex_none()
128 .px(px(12.))
129 .gap(px(12.))
130 .items_center()
131 .rounded(px(ITEM_RADIUS))
132 .cursor_pointer()
133 .text_size(px(14.))
134 .when(active, |item| {
135 item.bg(theme::popup_hover())
136 .font_weight(FontWeight::SEMIBOLD)
137 .text_color(theme::text())
138 })
139 .when(!active, |item| {
140 item.text_color(theme::text_strong())
141 .hover(|item| item.bg(theme::popup()))
142 })
143 .child(icon(
144 icon_name(section),
145 ITEM_ICON,
146 if active {
147 theme::accent_text()
148 } else {
149 theme::text_muted()
150 },
151 ))
152 .child(div().flex_1().min_w_0().truncate().child(label(section)))
153 .on_click(move |_, window, cx| on_select(section, window, cx))
154}
crates/app/src/settings/notifications.rs added +221 −0
@@ -0,0 +1,221 @@
1 use gpui_kit::component::{h_flex, v_flex};
2 use gpui_kit::*;
3
4 use super::rows::{Choice, caption, control_row, select, text_button, toggle_row};
5 use crate::notify::NotificationCenter;
6 use crate::notify::rules::{Corner, Settings};
7 use crate::notify::sounds::AlertSound;
8 use crate::theme;
9
10 type Accessor = fn(&mut Settings) -> &mut bool;
11 type SoundAccessor = fn(&mut Settings) -> &mut AlertSound;
12
13 struct Toggle {
14 id: &'static str,
15 title: &'static str,
16 detail: &'static str,
17 field: Accessor,
18 }
19
20 const APPEARANCE: [Toggle; 2] = [
21 Toggle {
22 id: "settings-preview",
23 title: "Show message preview",
24 detail: "Off: only \"New message\"",
25 field: |settings| &mut settings.preview,
26 },
27 Toggle {
28 id: "settings-flash",
29 title: "Flash taskbar when notifications are received",
30 detail: "On new messages, until you open the window",
31 field: |settings| &mut settings.flash,
32 },
33 ];
34
35 const NOTIFICATION_SOUND: Toggle = Toggle {
36 id: "settings-notification-sound",
37 title: "Play sounds with notifications",
38 detail: "",
39 field: |settings| &mut settings.sounds.notification_sound,
40 };
41
42 const URGENT_SOUND: Toggle = Toggle {
43 id: "settings-urgent-sound",
44 title: "Play sounds with urgent and priority contact notifications",
45 detail: "",
46 field: |settings| &mut settings.sounds.urgent_sound,
47 };
48
49 const CALL_SOUNDS: [Toggle; 2] = [
50 Toggle {
51 id: "settings-call-sound",
52 title: "Play sounds with incoming calls, requests to join, and meeting start notifications",
53 detail: "",
54 field: |settings| &mut settings.sounds.call_and_meeting_sound,
55 },
56 Toggle {
57 id: "settings-busy-sound",
58 title: "Play sounds when I'm busy or in a meeting",
59 detail: "",
60 field: |settings| &mut settings.sounds.sound_when_busy,
61 },
62 ];
63
64 const MENTIONS_ONLY: Toggle = Toggle {
65 id: "settings-mentions-only",
66 title: "Mentions only",
67 detail: "Direct messages and @mentions",
68 field: |settings| &mut settings.mentions_only,
69 };
70
71 const HIDE_IN_CALLS: Toggle = Toggle {
72 id: "settings-hide-in-calls",
73 title: "Hide notifications during calls and meetings",
74 detail: "No message toasts while a call is active",
75 field: |settings| &mut settings.mute_in_calls,
76 };
77
78 pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
79 let mut current = center.read(cx).settings().clone();
80 let corner = current.corner;
81 let sounds = current.sounds.clone();
82 let mut toggle = |toggle: &Toggle| {
83 let on = *(toggle.field)(&mut current);
84 toggle_element(center, toggle, on)
85 };
86 let appearance: Vec<Stateful<Div>> = APPEARANCE.iter().map(&mut toggle).collect();
87 let notification_sound = toggle(&NOTIFICATION_SOUND);
88 let urgent_sound = toggle(&URGENT_SOUND);
89 let call_sounds: Vec<Stateful<Div>> = CALL_SOUNDS.iter().map(&mut toggle).collect();
90 let mentions_only = toggle(&MENTIONS_ONLY);
91 let hide_in_calls = toggle(&HIDE_IN_CALLS);
92 let test_center = center.clone();
93 v_flex()
94 .w_full()
95 .child(caption("APPEARANCE AND SOUND"))
96 .children(appearance)
97 .child(control_row(
98 "Position on the screen",
99 "Corner of the main screen",
100 select(
101 "settings-position",
102 corner.label(),
103 false,
104 corner_choices(center, corner),
105 ),
106 ))
107 .child(control_row(
108 "Test notification",
109 "Shows a toast with the settings above",
110 text_button("settings-test-notification", "Send test notification").on_click(
111 move |_, _, cx| {
112 test_center.update(cx, |center, cx| center.send_test_notification(cx))
113 },
114 ),
115 ))
116 .child(caption("SOUND"))
117 .child(notification_sound)
118 .child(sound_row(
119 center,
120 (
121 "settings-notification-sound-type",
122 "settings-notification-sound-preview",
123 ),
124 "Notification sound",
125 &AlertSound::NORMAL,
126 sounds.notification_sound_type,
127 sounds.notification_sound,
128 |settings| &mut settings.sounds.notification_sound_type,
129 ))
130 .child(urgent_sound)
131 .child(sound_row(
132 center,
133 (
134 "settings-urgent-sound-type",
135 "settings-urgent-sound-preview",
136 ),
137 "Urgent sound",
138 &AlertSound::URGENT,
139 sounds.urgent_sound_type,
140 sounds.urgent_sound,
141 |settings| &mut settings.sounds.urgent_sound_type,
142 ))
143 .children(call_sounds)
144 .child(caption("WHAT YOU GET NOTIFIED FOR"))
145 .child(mentions_only)
146 .child(caption("MEETINGS AND CALLS"))
147 .child(hide_in_calls)
148 }
149
150 fn toggle_element(center: &Entity<NotificationCenter>, toggle: &Toggle, on: bool) -> Stateful<Div> {
151 let center = center.clone();
152 let field = toggle.field;
153 toggle_row(
154 toggle.id,
155 toggle.title,
156 toggle.detail,
157 theme::text_muted(),
158 on,
159 )
160 .on_click(move |_, _, cx| {
161 center.update(cx, |center, cx| {
162 center.update_settings(cx, |settings| {
163 let value = field(settings);
164 *value = !*value;
165 })
166 })
167 })
168 }
169
170 fn corner_choices(center: &Entity<NotificationCenter>, current: Corner) -> Vec<Choice> {
171 Corner::ALL
172 .into_iter()
173 .map(|corner| {
174 let center = center.clone();
175 Choice::new(corner.label(), corner == current, move |cx| {
176 center.update(cx, |center, cx| {
177 center.update_settings(cx, |settings| settings.corner = corner)
178 })
179 })
180 })
181 .collect()
182 }
183
184 fn sound_row(
185 center: &Entity<NotificationCenter>,
186 (id, preview_id): (&'static str, &'static str),
187 title: &'static str,
188 options: &'static [AlertSound],
189 current: AlertSound,
190 enabled: bool,
191 field: SoundAccessor,
192 ) -> Div {
193 let choices = options
194 .iter()
195 .map(|sound| {
196 let (center, sound) = (center.clone(), *sound);
197 Choice::new(sound.label(), sound == current, move |cx| {
198 center.update(cx, |center, cx| {
199 center.update_settings(cx, |settings| *field(settings) = sound);
200 center.preview_sound(sound.file_name(), cx);
201 })
202 })
203 })
204 .collect();
205 let preview_center = center.clone();
206 control_row(
207 title,
208 "",
209 h_flex()
210 .gap(px(8.))
211 .items_center()
212 .child(select(id, current.label(), !enabled, choices))
213 .child(
214 text_button(preview_id, "Preview").on_click(move |_, _, cx| {
215 preview_center.update(cx, |center, cx| {
216 center.preview_sound(current.file_name(), cx)
217 })
218 }),
219 ),
220 )
221 }
@@ -0,0 +1,221 @@
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::notify::NotificationCenter;
6use crate::notify::rules::{Corner, Settings};
7use crate::notify::sounds::AlertSound;
8use crate::theme;
9
10type Accessor = fn(&mut Settings) -> &mut bool;
11type SoundAccessor = fn(&mut Settings) -> &mut AlertSound;
12
13struct Toggle {
14 id: &'static str,
15 title: &'static str,
16 detail: &'static str,
17 field: Accessor,
18}
19
20const APPEARANCE: [Toggle; 2] = [
21 Toggle {
22 id: "settings-preview",
23 title: "Show message preview",
24 detail: "Off: only \"New message\"",
25 field: |settings| &mut settings.preview,
26 },
27 Toggle {
28 id: "settings-flash",
29 title: "Flash taskbar when notifications are received",
30 detail: "On new messages, until you open the window",
31 field: |settings| &mut settings.flash,
32 },
33];
34
35const NOTIFICATION_SOUND: Toggle = Toggle {
36 id: "settings-notification-sound",
37 title: "Play sounds with notifications",
38 detail: "",
39 field: |settings| &mut settings.sounds.notification_sound,
40};
41
42const URGENT_SOUND: Toggle = Toggle {
43 id: "settings-urgent-sound",
44 title: "Play sounds with urgent and priority contact notifications",
45 detail: "",
46 field: |settings| &mut settings.sounds.urgent_sound,
47};
48
49const CALL_SOUNDS: [Toggle; 2] = [
50 Toggle {
51 id: "settings-call-sound",
52 title: "Play sounds with incoming calls, requests to join, and meeting start notifications",
53 detail: "",
54 field: |settings| &mut settings.sounds.call_and_meeting_sound,
55 },
56 Toggle {
57 id: "settings-busy-sound",
58 title: "Play sounds when I'm busy or in a meeting",
59 detail: "",
60 field: |settings| &mut settings.sounds.sound_when_busy,
61 },
62];
63
64const MENTIONS_ONLY: Toggle = Toggle {
65 id: "settings-mentions-only",
66 title: "Mentions only",
67 detail: "Direct messages and @mentions",
68 field: |settings| &mut settings.mentions_only,
69};
70
71const HIDE_IN_CALLS: Toggle = Toggle {
72 id: "settings-hide-in-calls",
73 title: "Hide notifications during calls and meetings",
74 detail: "No message toasts while a call is active",
75 field: |settings| &mut settings.mute_in_calls,
76};
77
78pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
79 let mut current = center.read(cx).settings().clone();
80 let corner = current.corner;
81 let sounds = current.sounds.clone();
82 let mut toggle = |toggle: &Toggle| {
83 let on = *(toggle.field)(&mut current);
84 toggle_element(center, toggle, on)
85 };
86 let appearance: Vec<Stateful<Div>> = APPEARANCE.iter().map(&mut toggle).collect();
87 let notification_sound = toggle(&NOTIFICATION_SOUND);
88 let urgent_sound = toggle(&URGENT_SOUND);
89 let call_sounds: Vec<Stateful<Div>> = CALL_SOUNDS.iter().map(&mut toggle).collect();
90 let mentions_only = toggle(&MENTIONS_ONLY);
91 let hide_in_calls = toggle(&HIDE_IN_CALLS);
92 let test_center = center.clone();
93 v_flex()
94 .w_full()
95 .child(caption("APPEARANCE AND SOUND"))
96 .children(appearance)
97 .child(control_row(
98 "Position on the screen",
99 "Corner of the main screen",
100 select(
101 "settings-position",
102 corner.label(),
103 false,
104 corner_choices(center, corner),
105 ),
106 ))
107 .child(control_row(
108 "Test notification",
109 "Shows a toast with the settings above",
110 text_button("settings-test-notification", "Send test notification").on_click(
111 move |_, _, cx| {
112 test_center.update(cx, |center, cx| center.send_test_notification(cx))
113 },
114 ),
115 ))
116 .child(caption("SOUND"))
117 .child(notification_sound)
118 .child(sound_row(
119 center,
120 (
121 "settings-notification-sound-type",
122 "settings-notification-sound-preview",
123 ),
124 "Notification sound",
125 &AlertSound::NORMAL,
126 sounds.notification_sound_type,
127 sounds.notification_sound,
128 |settings| &mut settings.sounds.notification_sound_type,
129 ))
130 .child(urgent_sound)
131 .child(sound_row(
132 center,
133 (
134 "settings-urgent-sound-type",
135 "settings-urgent-sound-preview",
136 ),
137 "Urgent sound",
138 &AlertSound::URGENT,
139 sounds.urgent_sound_type,
140 sounds.urgent_sound,
141 |settings| &mut settings.sounds.urgent_sound_type,
142 ))
143 .children(call_sounds)
144 .child(caption("WHAT YOU GET NOTIFIED FOR"))
145 .child(mentions_only)
146 .child(caption("MEETINGS AND CALLS"))
147 .child(hide_in_calls)
148}
149
150fn toggle_element(center: &Entity<NotificationCenter>, toggle: &Toggle, on: bool) -> Stateful<Div> {
151 let center = center.clone();
152 let field = toggle.field;
153 toggle_row(
154 toggle.id,
155 toggle.title,
156 toggle.detail,
157 theme::text_muted(),
158 on,
159 )
160 .on_click(move |_, _, cx| {
161 center.update(cx, |center, cx| {
162 center.update_settings(cx, |settings| {
163 let value = field(settings);
164 *value = !*value;
165 })
166 })
167 })
168}
169
170fn corner_choices(center: &Entity<NotificationCenter>, current: Corner) -> Vec<Choice> {
171 Corner::ALL
172 .into_iter()
173 .map(|corner| {
174 let center = center.clone();
175 Choice::new(corner.label(), corner == current, move |cx| {
176 center.update(cx, |center, cx| {
177 center.update_settings(cx, |settings| settings.corner = corner)
178 })
179 })
180 })
181 .collect()
182}
183
184fn sound_row(
185 center: &Entity<NotificationCenter>,
186 (id, preview_id): (&'static str, &'static str),
187 title: &'static str,
188 options: &'static [AlertSound],
189 current: AlertSound,
190 enabled: bool,
191 field: SoundAccessor,
192) -> Div {
193 let choices = options
194 .iter()
195 .map(|sound| {
196 let (center, sound) = (center.clone(), *sound);
197 Choice::new(sound.label(), sound == current, move |cx| {
198 center.update(cx, |center, cx| {
199 center.update_settings(cx, |settings| *field(settings) = sound);
200 center.preview_sound(sound.file_name(), cx);
201 })
202 })
203 })
204 .collect();
205 let preview_center = center.clone();
206 control_row(
207 title,
208 "",
209 h_flex()
210 .gap(px(8.))
211 .items_center()
212 .child(select(id, current.label(), !enabled, choices))
213 .child(
214 text_button(preview_id, "Preview").on_click(move |_, _, cx| {
215 preview_center.update(cx, |center, cx| {
216 center.preview_sound(current.file_name(), cx)
217 })
218 }),
219 ),
220 )
221}
crates/app/src/settings/rows.rs added +212 −0
@@ -0,0 +1,212 @@
1 use std::rc::Rc;
2
3 use gpui_kit::assets::IconName;
4 use gpui_kit::base::Disableable as _;
5 use gpui_kit::component::{
6 button::Button,
7 h_flex,
8 menu::{DropdownMenu as _, PopupMenuItem},
9 v_flex,
10 };
11 use gpui_kit::prelude::FluentBuilder as _;
12 use gpui_kit::*;
13
14 use crate::theme;
15 use crate::views::widgets::icon;
16
17 pub const ROW_INSET: f32 = 12.;
18 pub const SELECT_WIDTH: f32 = 216.;
19 const ROW_PADDING: f32 = 12.;
20 const ROW_GAP: f32 = 12.;
21 const ROW_RADIUS: f32 = 8.;
22 const BUTTON_HEIGHT: f32 = 32.;
23 const BUTTON_RADIUS: f32 = 8.;
24 const SCROLL_MENU_AFTER: usize = 10;
25 const MENU_MAX_HEIGHT: f32 = 320.;
26
27 pub struct Choice {
28 pub label: SharedString,
29 pub checked: bool,
30 pub choose: Rc<dyn Fn(&mut App)>,
31 }
32
33 impl Choice {
34 pub fn new(
35 label: impl Into<SharedString>,
36 checked: bool,
37 choose: impl Fn(&mut App) + 'static,
38 ) -> Self {
39 Choice {
40 label: label.into(),
41 checked,
42 choose: Rc::new(choose),
43 }
44 }
45 }
46
47 pub fn switch(on: bool) -> Div {
48 div()
49 .w(px(36.))
50 .h(px(20.))
51 .flex_none()
52 .rounded_full()
53 .relative()
54 .bg(if on {
55 theme::accent()
56 } else {
57 theme::border_strong()
58 })
59 .child(
60 div()
61 .absolute()
62 .top(px(2.))
63 .left(px(if on { 18. } else { 2. }))
64 .size(px(16.))
65 .rounded_full()
66 .bg(theme::text()),
67 )
68 }
69
70 pub fn titled(
71 title: impl Into<SharedString>,
72 detail: impl Into<SharedString>,
73 detail_color: Hsla,
74 ) -> Div {
75 let detail = detail.into();
76 v_flex()
77 .flex_1()
78 .min_w(px(0.))
79 .gap(px(2.))
80 .child(
81 div()
82 .text_size(px(14.))
83 .line_height(px(20.))
84 .font_weight(FontWeight::SEMIBOLD)
85 .text_color(theme::text())
86 .child(title.into()),
87 )
88 .when(!detail.is_empty(), |column| {
89 column.child(
90 div()
91 .text_size(px(12.))
92 .line_height(px(16.))
93 .text_color(detail_color)
94 .child(detail),
95 )
96 })
97 }
98
99 pub fn row() -> Div {
100 h_flex()
101 .w_full()
102 .px(px(ROW_INSET))
103 .py(px(ROW_PADDING))
104 .gap(px(ROW_GAP))
105 .items_center()
106 .rounded(px(ROW_RADIUS))
107 }
108
109 pub fn control_row(
110 title: impl Into<SharedString>,
111 detail: impl Into<SharedString>,
112 control: impl IntoElement,
113 ) -> Div {
114 row()
115 .child(titled(title, detail, theme::text_muted()))
116 .child(control)
117 }
118
119 pub fn toggle_row(
120 id: impl Into<ElementId>,
121 title: impl Into<SharedString>,
122 detail: impl Into<SharedString>,
123 detail_color: Hsla,
124 on: bool,
125 ) -> Stateful<Div> {
126 row()
127 .id(id)
128 .cursor_pointer()
129 .hover(|row| row.bg(theme::popup_hover()))
130 .child(titled(title, detail, detail_color))
131 .child(switch(on))
132 }
133
134 pub fn caption(label: impl Into<SharedString>) -> Div {
135 div()
136 .w_full()
137 .px(px(ROW_INSET))
138 .pt(px(18.))
139 .pb(px(6.))
140 .text_size(px(12.))
141 .font_weight(FontWeight::SEMIBOLD)
142 .text_color(theme::text_muted())
143 .child(label.into())
144 }
145
146 pub fn text_button(id: impl Into<ElementId>, label: impl Into<SharedString>) -> Stateful<Div> {
147 div()
148 .id(id)
149 .h(px(BUTTON_HEIGHT))
150 .px(px(14.))
151 .flex()
152 .flex_none()
153 .items_center()
154 .rounded(px(BUTTON_RADIUS))
155 .border_1()
156 .border_color(theme::border_strong())
157 .cursor_pointer()
158 .text_size(px(13.))
159 .font_weight(FontWeight::SEMIBOLD)
160 .text_color(theme::text())
161 .hover(|button| button.bg(theme::popup_hover()))
162 .child(label.into())
163 }
164
165 pub fn select(
166 id: impl Into<ElementId>,
167 label: impl Into<SharedString>,
168 disabled: bool,
169 choices: Vec<Choice>,
170 ) -> impl IntoElement {
171 select_with_width(id, label, SELECT_WIDTH, disabled, choices)
172 }
173
174 pub fn select_with_width(
175 id: impl Into<ElementId>,
176 label: impl Into<SharedString>,
177 width: f32,
178 disabled: bool,
179 choices: Vec<Choice>,
180 ) -> impl IntoElement {
181 let scrollable = choices.len() > SCROLL_MENU_AFTER;
182 Button::new(id)
183 .outline()
184 .w(px(width))
185 .flex_none()
186 .disabled(disabled)
187 .child(
188 h_flex()
189 .w_full()
190 .min_w_0()
191 .gap(px(8.))
192 .items_center()
193 .justify_between()
194 .child(div().flex_1().min_w_0().truncate().child(label.into()))
195 .child(icon(IconName::ChevronDown, 12., theme::text_muted())),
196 )
197 .dropdown_menu(move |menu, _, _| {
198 let menu = if scrollable {
199 menu.max_h(px(MENU_MAX_HEIGHT)).scrollable(true)
200 } else {
201 menu
202 };
203 choices.iter().fold(menu, |menu, choice| {
204 let choose = choice.choose.clone();
205 menu.item(
206 PopupMenuItem::new(choice.label.clone())
207 .checked(choice.checked)
208 .on_click(move |_, _, cx| choose(cx)),
209 )
210 })
211 })
212 }
@@ -0,0 +1,212 @@
1use std::rc::Rc;
2
3use gpui_kit::assets::IconName;
4use gpui_kit::base::Disableable as _;
5use gpui_kit::component::{
6 button::Button,
7 h_flex,
8 menu::{DropdownMenu as _, PopupMenuItem},
9 v_flex,
10};
11use gpui_kit::prelude::FluentBuilder as _;
12use gpui_kit::*;
13
14use crate::theme;
15use crate::views::widgets::icon;
16
17pub const ROW_INSET: f32 = 12.;
18pub const SELECT_WIDTH: f32 = 216.;
19const ROW_PADDING: f32 = 12.;
20const ROW_GAP: f32 = 12.;
21const ROW_RADIUS: f32 = 8.;
22const BUTTON_HEIGHT: f32 = 32.;
23const BUTTON_RADIUS: f32 = 8.;
24const SCROLL_MENU_AFTER: usize = 10;
25const MENU_MAX_HEIGHT: f32 = 320.;
26
27pub struct Choice {
28 pub label: SharedString,
29 pub checked: bool,
30 pub choose: Rc<dyn Fn(&mut App)>,
31}
32
33impl Choice {
34 pub fn new(
35 label: impl Into<SharedString>,
36 checked: bool,
37 choose: impl Fn(&mut App) + 'static,
38 ) -> Self {
39 Choice {
40 label: label.into(),
41 checked,
42 choose: Rc::new(choose),
43 }
44 }
45}
46
47pub fn switch(on: bool) -> Div {
48 div()
49 .w(px(36.))
50 .h(px(20.))
51 .flex_none()
52 .rounded_full()
53 .relative()
54 .bg(if on {
55 theme::accent()
56 } else {
57 theme::border_strong()
58 })
59 .child(
60 div()
61 .absolute()
62 .top(px(2.))
63 .left(px(if on { 18. } else { 2. }))
64 .size(px(16.))
65 .rounded_full()
66 .bg(theme::text()),
67 )
68}
69
70pub fn titled(
71 title: impl Into<SharedString>,
72 detail: impl Into<SharedString>,
73 detail_color: Hsla,
74) -> Div {
75 let detail = detail.into();
76 v_flex()
77 .flex_1()
78 .min_w(px(0.))
79 .gap(px(2.))
80 .child(
81 div()
82 .text_size(px(14.))
83 .line_height(px(20.))
84 .font_weight(FontWeight::SEMIBOLD)
85 .text_color(theme::text())
86 .child(title.into()),
87 )
88 .when(!detail.is_empty(), |column| {
89 column.child(
90 div()
91 .text_size(px(12.))
92 .line_height(px(16.))
93 .text_color(detail_color)
94 .child(detail),
95 )
96 })
97}
98
99pub fn row() -> Div {
100 h_flex()
101 .w_full()
102 .px(px(ROW_INSET))
103 .py(px(ROW_PADDING))
104 .gap(px(ROW_GAP))
105 .items_center()
106 .rounded(px(ROW_RADIUS))
107}
108
109pub fn control_row(
110 title: impl Into<SharedString>,
111 detail: impl Into<SharedString>,
112 control: impl IntoElement,
113) -> Div {
114 row()
115 .child(titled(title, detail, theme::text_muted()))
116 .child(control)
117}
118
119pub fn toggle_row(
120 id: impl Into<ElementId>,
121 title: impl Into<SharedString>,
122 detail: impl Into<SharedString>,
123 detail_color: Hsla,
124 on: bool,
125) -> Stateful<Div> {
126 row()
127 .id(id)
128 .cursor_pointer()
129 .hover(|row| row.bg(theme::popup_hover()))
130 .child(titled(title, detail, detail_color))
131 .child(switch(on))
132}
133
134pub fn caption(label: impl Into<SharedString>) -> Div {
135 div()
136 .w_full()
137 .px(px(ROW_INSET))
138 .pt(px(18.))
139 .pb(px(6.))
140 .text_size(px(12.))
141 .font_weight(FontWeight::SEMIBOLD)
142 .text_color(theme::text_muted())
143 .child(label.into())
144}
145
146pub fn text_button(id: impl Into<ElementId>, label: impl Into<SharedString>) -> Stateful<Div> {
147 div()
148 .id(id)
149 .h(px(BUTTON_HEIGHT))
150 .px(px(14.))
151 .flex()
152 .flex_none()
153 .items_center()
154 .rounded(px(BUTTON_RADIUS))
155 .border_1()
156 .border_color(theme::border_strong())
157 .cursor_pointer()
158 .text_size(px(13.))
159 .font_weight(FontWeight::SEMIBOLD)
160 .text_color(theme::text())
161 .hover(|button| button.bg(theme::popup_hover()))
162 .child(label.into())
163}
164
165pub fn select(
166 id: impl Into<ElementId>,
167 label: impl Into<SharedString>,
168 disabled: bool,
169 choices: Vec<Choice>,
170) -> impl IntoElement {
171 select_with_width(id, label, SELECT_WIDTH, disabled, choices)
172}
173
174pub fn select_with_width(
175 id: impl Into<ElementId>,
176 label: impl Into<SharedString>,
177 width: f32,
178 disabled: bool,
179 choices: Vec<Choice>,
180) -> impl IntoElement {
181 let scrollable = choices.len() > SCROLL_MENU_AFTER;
182 Button::new(id)
183 .outline()
184 .w(px(width))
185 .flex_none()
186 .disabled(disabled)
187 .child(
188 h_flex()
189 .w_full()
190 .min_w_0()
191 .gap(px(8.))
192 .items_center()
193 .justify_between()
194 .child(div().flex_1().min_w_0().truncate().child(label.into()))
195 .child(icon(IconName::ChevronDown, 12., theme::text_muted())),
196 )
197 .dropdown_menu(move |menu, _, _| {
198 let menu = if scrollable {
199 menu.max_h(px(MENU_MAX_HEIGHT)).scrollable(true)
200 } else {
201 menu
202 };
203 choices.iter().fold(menu, |menu, choice| {
204 let choose = choice.choose.clone();
205 menu.item(
206 PopupMenuItem::new(choice.label.clone())
207 .checked(choice.checked)
208 .on_click(move |_, _, cx| choose(cx)),
209 )
210 })
211 })
212}
crates/app/src/views/conversation.rs +1 −1
@@ -641,7 +641,7 @@ impl ConversationView {
641 641 | AppEvent::Forward
642 642 | AppEvent::ImageViewer
643 643 | AppEvent::StatusMessage
644 | AppEvent::NotificationSettings
644 | AppEvent::Settings(_)
645 645 | AppEvent::Profile
646 646 | AppEvent::CallHistory
647 647 | AppEvent::Ring
@@ -641,7 +641,7 @@ impl ConversationView {
641 | AppEvent::Forward
641 | AppEvent::Forward
642 | AppEvent::ImageViewer
642 | AppEvent::ImageViewer
643 | AppEvent::StatusMessage
643 | AppEvent::StatusMessage
644 | AppEvent::NotificationSettings
644 | AppEvent::Settings(_)
645 | AppEvent::Profile
645 | AppEvent::Profile
646 | AppEvent::CallHistory
646 | AppEvent::CallHistory
647 | AppEvent::Ring
647 | AppEvent::Ring
crates/app/src/views/prejoin_view.rs +1 −1
@@ -58,7 +58,7 @@ struct DeviceSelect {
58 58 enabled: bool,
59 59 }
60 60
61 fn demo_devices() -> DeviceLists {
61 pub(crate) fn demo_devices() -> DeviceLists {
62 62 let device = |index: u16, name: &str| AudioDevice {
63 63 index,
64 64 guid: format!("demo-{name}"),
@@ -58,7 +58,7 @@ struct DeviceSelect {
58 enabled: bool,
58 enabled: bool,
59}
59}
60
60
61fn demo_devices() -> DeviceLists {
61pub(crate) fn demo_devices() -> DeviceLists {
62 let device = |index: u16, name: &str| AudioDevice {
62 let device = |index: u16, name: &str| AudioDevice {
63 index,
63 index,
64 guid: format!("demo-{name}"),
64 guid: format!("demo-{name}"),
crates/app/src/views/shell.rs +42 −9
@@ -40,6 +40,8 @@ use crate::app_state::{AppEvent, AppState, Selection, selection_for};
40 40 use crate::call::{CallMedia, CallWindows, ZoomStep};
41 41 use crate::notice::NoticeAction;
42 42 use crate::notify::NotificationCenter;
43 use crate::settings::{SettingsDialog, SettingsDialogEvent};
44 use crate::settings_section::SettingsSection;
43 45 use crate::sidebar_model::Step;
44 46 use crate::theme;
45 47 use crate::updater::{self, IdleInputs, UpdateStatus};
@@ -118,6 +120,7 @@ pub struct AppShell {
118 120 status_dialog: Option<Entity<StatusMessageDialog>>,
119 121 shortcuts_dialog: Option<Entity<ShortcutsDialog>>,
120 122 agent_dialog: Option<Entity<StartDialog>>,
123 settings_dialog: Option<Entity<SettingsDialog>>,
121 124 profile_card: Option<Entity<ProfileCard>>,
122 125 focus_handle: FocusHandle,
123 126 call_window_fullscreen: bool,
@@ -202,9 +205,9 @@ impl AppShell {
202 205 cx.subscribe(
203 206 &activity_panel,
204 207 |this, _, event: &ActivityPanelEvent, cx| match event {
205 ActivityPanelEvent::OpenSettings => this
206 .notifications
207 .update(cx, |center, cx| center.open_settings(cx)),
208 ActivityPanelEvent::OpenSettings => this.state.update(cx, |state, cx| {
209 state.open_settings(SettingsSection::Notifications, cx)
210 }),
208 211 ActivityPanelEvent::Open {
209 212 conversation_id,
210 213 message_id,
@@ -227,9 +230,9 @@ impl AppShell {
227 230 AgentRunsEvent::StartRequested(request) => {
228 231 this.open_agent_dialog(request.clone(), window, cx)
229 232 }
230 AgentRunsEvent::OpenSettings => this
231 .notifications
232 .update(cx, |center, cx| center.open_agent_settings(cx)),
233 AgentRunsEvent::OpenSettings => {
234 this.open_settings(SettingsSection::Agents, window, cx)
235 }
233 236 AgentRunsEvent::Finished(_) => {}
234 237 },
235 238 )
@@ -253,9 +256,8 @@ impl AppShell {
253 256 if matches!(event, AppEvent::StatusMessage) {
254 257 this.open_status_dialog(window, cx);
255 258 }
256 if matches!(event, AppEvent::NotificationSettings) {
257 this.notifications
258 .update(cx, |center, cx| center.open_settings(cx));
259 if let AppEvent::Settings(section) = event {
260 this.open_settings(*section, window, cx);
259 261 }
260 262 if matches!(event, AppEvent::Profile) {
261 263 this.open_profile_card(window, cx);
@@ -300,6 +302,7 @@ impl AppShell {
300 302 status_dialog: None,
301 303 shortcuts_dialog: None,
302 304 agent_dialog: None,
305 settings_dialog: None,
303 306 profile_card: None,
304 307 focus_handle,
305 308 call_window_fullscreen: false,
@@ -559,6 +562,34 @@ impl AppShell {
559 562 cx.notify();
560 563 }
561 564
565 fn open_settings(
566 &mut self,
567 section: SettingsSection,
568 window: &mut Window,
569 cx: &mut Context<Self>,
570 ) {
571 if let Some(dialog) = &self.settings_dialog {
572 dialog.update(cx, |dialog, cx| dialog.show(section, window, cx));
573 return;
574 }
575 self.close_image_viewer(window, cx);
576 self.switcher = None;
577 let (app, center) = (self.state.clone(), self.notifications.clone());
578 let dialog = cx.new(|cx| SettingsDialog::new(app, center, section, window, cx));
579 cx.subscribe_in(
580 &dialog,
581 window,
582 |this, _, _: &SettingsDialogEvent, window, cx| {
583 this.settings_dialog = None;
584 this.restore_focus(window, cx);
585 cx.notify();
586 },
587 )
588 .detach();
589 self.settings_dialog = Some(dialog);
590 cx.notify();
591 }
592
562 593 fn toggle_shortcuts_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
563 594 if self.shortcuts_dialog.take().is_some() {
564 595 self.restore_focus(window, cx);
@@ -768,6 +799,7 @@ impl Render for AppShell {
768 799 self.status_dialog.is_some(),
769 800 self.shortcuts_dialog.is_some(),
770 801 self.agent_dialog.is_some(),
802 self.settings_dialog.is_some(),
771 803 ]
772 804 .into_iter()
773 805 .filter(|open| *open)
@@ -992,6 +1024,7 @@ impl Render for AppShell {
992 1024 .children(self.status_dialog.clone())
993 1025 .children(self.shortcuts_dialog.clone())
994 1026 .children(self.agent_dialog.clone())
1027 .children(self.settings_dialog.clone())
995 1028 .children(self.profile_card.clone())
996 1029 .child(crate::frame_log::probe("last"))
997 1030 }
@@ -40,6 +40,8 @@ use crate::app_state::{AppEvent, AppState, Selection, selection_for};
40use crate::call::{CallMedia, CallWindows, ZoomStep};
40use crate::call::{CallMedia, CallWindows, ZoomStep};
41use crate::notice::NoticeAction;
41use crate::notice::NoticeAction;
42use crate::notify::NotificationCenter;
42use crate::notify::NotificationCenter;
43use crate::settings::{SettingsDialog, SettingsDialogEvent};
44use crate::settings_section::SettingsSection;
43use crate::sidebar_model::Step;
45use crate::sidebar_model::Step;
44use crate::theme;
46use crate::theme;
45use crate::updater::{self, IdleInputs, UpdateStatus};
47use crate::updater::{self, IdleInputs, UpdateStatus};
@@ -118,6 +120,7 @@ pub struct AppShell {
118 status_dialog: Option<Entity<StatusMessageDialog>>,
120 status_dialog: Option<Entity<StatusMessageDialog>>,
119 shortcuts_dialog: Option<Entity<ShortcutsDialog>>,
121 shortcuts_dialog: Option<Entity<ShortcutsDialog>>,
120 agent_dialog: Option<Entity<StartDialog>>,
122 agent_dialog: Option<Entity<StartDialog>>,
123 settings_dialog: Option<Entity<SettingsDialog>>,
121 profile_card: Option<Entity<ProfileCard>>,
124 profile_card: Option<Entity<ProfileCard>>,
122 focus_handle: FocusHandle,
125 focus_handle: FocusHandle,
123 call_window_fullscreen: bool,
126 call_window_fullscreen: bool,
@@ -202,9 +205,9 @@ impl AppShell {
202 cx.subscribe(
205 cx.subscribe(
203 &activity_panel,
206 &activity_panel,
204 |this, _, event: &ActivityPanelEvent, cx| match event {
207 |this, _, event: &ActivityPanelEvent, cx| match event {
205 ActivityPanelEvent::OpenSettings => this
208 ActivityPanelEvent::OpenSettings => this.state.update(cx, |state, cx| {
206 .notifications
209 state.open_settings(SettingsSection::Notifications, cx)
207 .update(cx, |center, cx| center.open_settings(cx)),
210 }),
208 ActivityPanelEvent::Open {
211 ActivityPanelEvent::Open {
209 conversation_id,
212 conversation_id,
210 message_id,
213 message_id,
@@ -227,9 +230,9 @@ impl AppShell {
227 AgentRunsEvent::StartRequested(request) => {
230 AgentRunsEvent::StartRequested(request) => {
228 this.open_agent_dialog(request.clone(), window, cx)
231 this.open_agent_dialog(request.clone(), window, cx)
229 }
232 }
230 AgentRunsEvent::OpenSettings => this
233 AgentRunsEvent::OpenSettings => {
231 .notifications
234 this.open_settings(SettingsSection::Agents, window, cx)
232 .update(cx, |center, cx| center.open_agent_settings(cx)),
235 }
233 AgentRunsEvent::Finished(_) => {}
236 AgentRunsEvent::Finished(_) => {}
234 },
237 },
235 )
238 )
@@ -253,9 +256,8 @@ impl AppShell {
253 if matches!(event, AppEvent::StatusMessage) {
256 if matches!(event, AppEvent::StatusMessage) {
254 this.open_status_dialog(window, cx);
257 this.open_status_dialog(window, cx);
255 }
258 }
256 if matches!(event, AppEvent::NotificationSettings) {
259 if let AppEvent::Settings(section) = event {
257 this.notifications
260 this.open_settings(*section, window, cx);
258 .update(cx, |center, cx| center.open_settings(cx));
259 }
261 }
260 if matches!(event, AppEvent::Profile) {
262 if matches!(event, AppEvent::Profile) {
261 this.open_profile_card(window, cx);
263 this.open_profile_card(window, cx);
@@ -300,6 +302,7 @@ impl AppShell {
300 status_dialog: None,
302 status_dialog: None,
301 shortcuts_dialog: None,
303 shortcuts_dialog: None,
302 agent_dialog: None,
304 agent_dialog: None,
305 settings_dialog: None,
303 profile_card: None,
306 profile_card: None,
304 focus_handle,
307 focus_handle,
305 call_window_fullscreen: false,
308 call_window_fullscreen: false,
@@ -559,6 +562,34 @@ impl AppShell {
559 cx.notify();
562 cx.notify();
560 }
563 }
561
564
565 fn open_settings(
566 &mut self,
567 section: SettingsSection,
568 window: &mut Window,
569 cx: &mut Context<Self>,
570 ) {
571 if let Some(dialog) = &self.settings_dialog {
572 dialog.update(cx, |dialog, cx| dialog.show(section, window, cx));
573 return;
574 }
575 self.close_image_viewer(window, cx);
576 self.switcher = None;
577 let (app, center) = (self.state.clone(), self.notifications.clone());
578 let dialog = cx.new(|cx| SettingsDialog::new(app, center, section, window, cx));
579 cx.subscribe_in(
580 &dialog,
581 window,
582 |this, _, _: &SettingsDialogEvent, window, cx| {
583 this.settings_dialog = None;
584 this.restore_focus(window, cx);
585 cx.notify();
586 },
587 )
588 .detach();
589 self.settings_dialog = Some(dialog);
590 cx.notify();
591 }
592
562 fn toggle_shortcuts_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
593 fn toggle_shortcuts_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
563 if self.shortcuts_dialog.take().is_some() {
594 if self.shortcuts_dialog.take().is_some() {
564 self.restore_focus(window, cx);
595 self.restore_focus(window, cx);
@@ -768,6 +799,7 @@ impl Render for AppShell {
768 self.status_dialog.is_some(),
799 self.status_dialog.is_some(),
769 self.shortcuts_dialog.is_some(),
800 self.shortcuts_dialog.is_some(),
770 self.agent_dialog.is_some(),
801 self.agent_dialog.is_some(),
802 self.settings_dialog.is_some(),
771 ]
803 ]
772 .into_iter()
804 .into_iter()
773 .filter(|open| *open)
805 .filter(|open| *open)
@@ -992,6 +1024,7 @@ impl Render for AppShell {
992 .children(self.status_dialog.clone())
1024 .children(self.status_dialog.clone())
993 .children(self.shortcuts_dialog.clone())
1025 .children(self.shortcuts_dialog.clone())
994 .children(self.agent_dialog.clone())
1026 .children(self.agent_dialog.clone())
1027 .children(self.settings_dialog.clone())
995 .children(self.profile_card.clone())
1028 .children(self.profile_card.clone())
996 .child(crate::frame_log::probe("last"))
1029 .child(crate::frame_log::probe("last"))
997 }
1030 }
crates/app/src/views/status_menu.rs +23 −175
@@ -7,17 +7,14 @@ use gpui_kit::component::{
7 7 menu::{DropdownMenu as _, PopupMenu, PopupMenuItem},
8 8 v_flex,
9 9 };
10 use gpui_kit::prelude::FluentBuilder as _;
11 10 use gpui_kit::*;
12 use teams_core::{
13 ChatSection, ForcedAvailability, ForcedKind, PresenceStatus, TranslationBehavior,
14 WorkLocationKind,
15 };
11 use teams_core::{ForcedAvailability, ForcedKind, PresenceStatus, WorkLocationKind};
16 12
17 13 use super::avatar::{person_avatar, with_presence};
18 14 use super::widgets::{icon, symbol};
19 15 use crate::app_state::AppState;
20 16 use crate::data::{Person, PresenceKind};
17 use crate::settings_section::SettingsSection;
21 18 use crate::own_status::{
22 19 STATUS_CHOICES, STATUS_DURATIONS, StateSummary, StatusDuration, choice_label, duration_target,
23 20 presence_kind_for, state_summary, work_location_label,
@@ -33,12 +30,6 @@ const OWN_STATUS_BUTTON_SIZE: f32 = TITLE_AVATAR_SIZE + 2. * (1. + RING_WIDTH +
33 30 const MENU_ICON_SIZE: f32 = 14.;
34 31 const ICON_COLUMN: f32 = 16.;
35 32 const HEADER_INSET: f32 = 24.;
36 const SWITCH_WIDTH: f32 = 28.;
37 const SWITCH_HEIGHT: f32 = 16.;
38 const SWITCH_THUMB: f32 = 12.;
39 const SWITCH_PADDING: f32 = 2.;
40 const TOGGLE_LABEL_WIDTH: f32 = 270.;
41 const LANGUAGE_LIST_HEIGHT: f32 = 320.;
42 33
43 34 #[derive(Clone)]
44 35 struct MenuContext {
@@ -192,6 +183,8 @@ fn status_menu(
192 183 let header_context = context.clone();
193 184 let message_app = context.app.clone();
194 185 let settings_app = context.app.clone();
186 let chat_list_app = context.app.clone();
187 let translation_app = context.app.clone();
195 188 let call_app = context.app.clone();
196 189 let row_label = match &context.summary.until {
197 190 Some(until) => format!("{} {until}", context.summary.label),
@@ -222,8 +215,22 @@ fn status_menu(
222 215 }),
223 216 )
224 217 .separator()
225 .item(chat_list_item(context, window, cx))
226 .item(translation_item(context, window, cx))
218 .item(
219 PopupMenuItem::new("Chat list")
220 .icon(menu_icon(IconName::LayoutList))
221 .on_click(move |_, _, cx| {
222 chat_list_app
223 .update(cx, |state, cx| state.open_settings(SettingsSection::Chats, cx));
224 }),
225 )
226 .item(
227 PopupMenuItem::new("Translation")
228 .icon(menu_icon(IconName::Languages))
229 .on_click(move |_, _, cx| {
230 translation_app
231 .update(cx, |state, cx| state.open_settings(SettingsSection::General, cx));
232 }),
233 )
227 234 .item(
228 235 PopupMenuItem::new("Make a test call")
229 236 .icon(menu_icon(IconName::Phone))
@@ -235,7 +242,9 @@ fn status_menu(
235 242 PopupMenuItem::new("Notification settings")
236 243 .icon(menu_icon(IconName::Settings))
237 244 .on_click(move |_, _, cx| {
238 settings_app.update(cx, |state, cx| state.open_notification_settings(cx));
245 settings_app.update(cx, |state, cx| {
246 state.open_settings(SettingsSection::Notifications, cx)
247 });
239 248 }),
240 249 );
241 250 if !demo {
@@ -250,167 +259,6 @@ fn status_menu(
250 259 )
251 260 }
252 261
253 fn chat_list_item(
254 context: &MenuContext,
255 window: &mut Window,
256 cx: &mut Context<PopupMenu>,
257 ) -> PopupMenuItem {
258 let app = context.app.clone();
259 let submenu = PopupMenu::build(window, cx, move |menu, _, cx| {
260 let settings = app.read(cx).directory.section_settings;
261 menu.item(section_toggle(
262 &app,
263 ChatSection::Muted,
264 "Show muted chats in own section",
265 settings.enabled(ChatSection::Muted),
266 ))
267 });
268 PopupMenuItem::submenu("Chat list", submenu).icon(menu_icon(IconName::LayoutList))
269 }
270
271 fn translation_item(
272 context: &MenuContext,
273 window: &mut Window,
274 cx: &mut Context<PopupMenu>,
275 ) -> PopupMenuItem {
276 let app = context.app.clone();
277 let submenu = PopupMenu::build(window, cx, move |menu, window, cx| {
278 translation_menu(menu, window, cx, &app)
279 });
280 PopupMenuItem::submenu("Translation", submenu).icon(menu_icon(IconName::Languages))
281 }
282
283 fn translation_menu(
284 menu: PopupMenu,
285 window: &mut Window,
286 cx: &mut Context<PopupMenu>,
287 app: &Entity<AppState>,
288 ) -> PopupMenu {
289 let state = app.read(cx);
290 if state.translation.settings.is_none() {
291 return menu.item(PopupMenuItem::label("Translation settings not loaded yet"));
292 }
293 let target = state.translation.target();
294 let behavior = state.translation.behavior();
295 let languages = state.translation.languages.clone();
296 let never: Vec<(String, String)> = state
297 .translation
298 .display_codes()
299 .into_iter()
300 .filter(|code| *code != target)
301 .map(|code| {
302 let name = state.translation.language_name(&code);
303 (code, name)
304 })
305 .collect();
306 let target_label = format!("Translate to {}", state.translation.language_name(&target));
307 let target_app = app.clone();
308 let mut menu = menu
309 .check_side(Side::Right)
310 .min_w(px(MENU_WIDTH))
311 .submenu_with_icon(None, target_label, window, cx, move |submenu, _, _| {
312 languages.iter().fold(
313 submenu
314 .check_side(Side::Right)
315 .max_h(px(LANGUAGE_LIST_HEIGHT))
316 .scrollable(true),
317 |submenu, language| {
318 let (app, code) = (target_app.clone(), language.code.clone());
319 submenu.item(
320 PopupMenuItem::new(language.name.clone())
321 .checked(language.code == target)
322 .on_click(move |_, _, cx| {
323 app.update(cx, |state, cx| state.set_translation_target(&code, cx));
324 }),
325 )
326 },
327 )
328 });
329 menu = menu.separator();
330 for (label, choice) in [
331 ("Ask me before translating", TranslationBehavior::Ask),
332 ("Auto-translate all messages", TranslationBehavior::Auto),
333 ("Never translate", TranslationBehavior::Never),
334 ] {
335 let app = app.clone();
336 menu = menu.item(
337 PopupMenuItem::new(label)
338 .checked(behavior == choice)
339 .on_click(move |_, _, cx| {
340 app.update(cx, |state, cx| state.set_translation_behavior(choice, cx));
341 }),
342 );
343 }
344 menu = menu
345 .separator()
346 .item(PopupMenuItem::label("Never translate messages in"));
347 if never.is_empty() {
348 return menu.item(PopupMenuItem::label("No languages"));
349 }
350 for (code, name) in never {
351 let app = app.clone();
352 menu = menu.item(
353 PopupMenuItem::element(move |_, _| {
354 h_flex()
355 .w(px(TOGGLE_LABEL_WIDTH))
356 .gap(px(12.))
357 .items_center()
358 .justify_between()
359 .child(div().flex_1().min_w_0().truncate().child(name.clone()))
360 .child(menu_icon(IconName::X))
361 })
362 .on_click(move |_, _, cx| {
363 app.update(cx, |state, cx| state.allow_translating_language(&code, cx));
364 }),
365 );
366 }
367 menu
368 }
369
370 fn section_toggle(
371 app: &Entity<AppState>,
372 section: ChatSection,
373 label: &'static str,
374 enabled: bool,
375 ) -> PopupMenuItem {
376 let app = app.clone();
377 PopupMenuItem::element(move |_, _| {
378 h_flex()
379 .w(px(TOGGLE_LABEL_WIDTH))
380 .gap(px(12.))
381 .items_center()
382 .justify_between()
383 .child(div().flex_1().min_w_0().truncate().child(label))
384 .child(switch(enabled))
385 })
386 .on_click(move |_, _, cx| {
387 app.update(cx, |state, cx| {
388 state.set_chat_section(section, !enabled, cx)
389 });
390 })
391 }
392
393 fn switch(enabled: bool) -> Div {
394 let thumb = div()
395 .size(px(SWITCH_THUMB))
396 .rounded_full()
397 .bg(theme::text_strong());
398 h_flex()
399 .w(px(SWITCH_WIDTH))
400 .h(px(SWITCH_HEIGHT))
401 .flex_none()
402 .p(px(SWITCH_PADDING))
403 .items_center()
404 .rounded_full()
405 .bg(if enabled {
406 theme::accent()
407 } else {
408 theme::badge_muted()
409 })
410 .when(enabled, |track| track.justify_end())
411 .child(thumb)
412 }
413
414 262 fn work_location_icon(kind: Option<WorkLocationKind>) -> gpui_kit::component::Icon {
415 263 menu_icon(match kind {
416 264 Some(WorkLocationKind::Office) => IconName::Building2,
@@ -7,17 +7,14 @@ use gpui_kit::component::{
7 menu::{DropdownMenu as _, PopupMenu, PopupMenuItem},
7 menu::{DropdownMenu as _, PopupMenu, PopupMenuItem},
8 v_flex,
8 v_flex,
9};
9};
10use gpui_kit::prelude::FluentBuilder as _;
11use gpui_kit::*;
10use gpui_kit::*;
12use teams_core::{
11use teams_core::{ForcedAvailability, ForcedKind, PresenceStatus, WorkLocationKind};
13 ChatSection, ForcedAvailability, ForcedKind, PresenceStatus, TranslationBehavior,
14 WorkLocationKind,
15};
16
12
17use super::avatar::{person_avatar, with_presence};
13use super::avatar::{person_avatar, with_presence};
18use super::widgets::{icon, symbol};
14use super::widgets::{icon, symbol};
19use crate::app_state::AppState;
15use crate::app_state::AppState;
20use crate::data::{Person, PresenceKind};
16use crate::data::{Person, PresenceKind};
17use crate::settings_section::SettingsSection;
21use crate::own_status::{
18use crate::own_status::{
22 STATUS_CHOICES, STATUS_DURATIONS, StateSummary, StatusDuration, choice_label, duration_target,
19 STATUS_CHOICES, STATUS_DURATIONS, StateSummary, StatusDuration, choice_label, duration_target,
23 presence_kind_for, state_summary, work_location_label,
20 presence_kind_for, state_summary, work_location_label,
@@ -33,12 +30,6 @@ const OWN_STATUS_BUTTON_SIZE: f32 = TITLE_AVATAR_SIZE + 2. * (1. + RING_WIDTH +
33const MENU_ICON_SIZE: f32 = 14.;
30const MENU_ICON_SIZE: f32 = 14.;
34const ICON_COLUMN: f32 = 16.;
31const ICON_COLUMN: f32 = 16.;
35const HEADER_INSET: f32 = 24.;
32const HEADER_INSET: f32 = 24.;
36const SWITCH_WIDTH: f32 = 28.;
37const SWITCH_HEIGHT: f32 = 16.;
38const SWITCH_THUMB: f32 = 12.;
39const SWITCH_PADDING: f32 = 2.;
40const TOGGLE_LABEL_WIDTH: f32 = 270.;
41const LANGUAGE_LIST_HEIGHT: f32 = 320.;
42
33
43#[derive(Clone)]
34#[derive(Clone)]
44struct MenuContext {
35struct MenuContext {
@@ -192,6 +183,8 @@ fn status_menu(
192 let header_context = context.clone();
183 let header_context = context.clone();
193 let message_app = context.app.clone();
184 let message_app = context.app.clone();
194 let settings_app = context.app.clone();
185 let settings_app = context.app.clone();
186 let chat_list_app = context.app.clone();
187 let translation_app = context.app.clone();
195 let call_app = context.app.clone();
188 let call_app = context.app.clone();
196 let row_label = match &context.summary.until {
189 let row_label = match &context.summary.until {
197 Some(until) => format!("{} {until}", context.summary.label),
190 Some(until) => format!("{} {until}", context.summary.label),
@@ -222,8 +215,22 @@ fn status_menu(
222 }),
215 }),
223 )
216 )
224 .separator()
217 .separator()
225 .item(chat_list_item(context, window, cx))
218 .item(
226 .item(translation_item(context, window, cx))
219 PopupMenuItem::new("Chat list")
220 .icon(menu_icon(IconName::LayoutList))
221 .on_click(move |_, _, cx| {
222 chat_list_app
223 .update(cx, |state, cx| state.open_settings(SettingsSection::Chats, cx));
224 }),
225 )
226 .item(
227 PopupMenuItem::new("Translation")
228 .icon(menu_icon(IconName::Languages))
229 .on_click(move |_, _, cx| {
230 translation_app
231 .update(cx, |state, cx| state.open_settings(SettingsSection::General, cx));
232 }),
233 )
227 .item(
234 .item(
228 PopupMenuItem::new("Make a test call")
235 PopupMenuItem::new("Make a test call")
229 .icon(menu_icon(IconName::Phone))
236 .icon(menu_icon(IconName::Phone))
@@ -235,7 +242,9 @@ fn status_menu(
235 PopupMenuItem::new("Notification settings")
242 PopupMenuItem::new("Notification settings")
236 .icon(menu_icon(IconName::Settings))
243 .icon(menu_icon(IconName::Settings))
237 .on_click(move |_, _, cx| {
244 .on_click(move |_, _, cx| {
238 settings_app.update(cx, |state, cx| state.open_notification_settings(cx));
245 settings_app.update(cx, |state, cx| {
246 state.open_settings(SettingsSection::Notifications, cx)
247 });
239 }),
248 }),
240 );
249 );
241 if !demo {
250 if !demo {
@@ -250,167 +259,6 @@ fn status_menu(
250 )
259 )
251}
260}
252
261
253fn chat_list_item(
254 context: &MenuContext,
255 window: &mut Window,
256 cx: &mut Context<PopupMenu>,
257) -> PopupMenuItem {
258 let app = context.app.clone();
259 let submenu = PopupMenu::build(window, cx, move |menu, _, cx| {
260 let settings = app.read(cx).directory.section_settings;
261 menu.item(section_toggle(
262 &app,
263 ChatSection::Muted,
264 "Show muted chats in own section",
265 settings.enabled(ChatSection::Muted),
266 ))
267 });
268 PopupMenuItem::submenu("Chat list", submenu).icon(menu_icon(IconName::LayoutList))
269}
270
271fn translation_item(
272 context: &MenuContext,
273 window: &mut Window,
274 cx: &mut Context<PopupMenu>,
275) -> PopupMenuItem {
276 let app = context.app.clone();
277 let submenu = PopupMenu::build(window, cx, move |menu, window, cx| {
278 translation_menu(menu, window, cx, &app)
279 });
280 PopupMenuItem::submenu("Translation", submenu).icon(menu_icon(IconName::Languages))
281}
282
283fn translation_menu(
284 menu: PopupMenu,
285 window: &mut Window,
286 cx: &mut Context<PopupMenu>,
287 app: &Entity<AppState>,
288) -> PopupMenu {
289 let state = app.read(cx);
290 if state.translation.settings.is_none() {
291 return menu.item(PopupMenuItem::label("Translation settings not loaded yet"));
292 }
293 let target = state.translation.target();
294 let behavior = state.translation.behavior();
295 let languages = state.translation.languages.clone();
296 let never: Vec<(String, String)> = state
297 .translation
298 .display_codes()
299 .into_iter()
300 .filter(|code| *code != target)
301 .map(|code| {
302 let name = state.translation.language_name(&code);
303 (code, name)
304 })
305 .collect();
306 let target_label = format!("Translate to {}", state.translation.language_name(&target));
307 let target_app = app.clone();
308 let mut menu = menu
309 .check_side(Side::Right)
310 .min_w(px(MENU_WIDTH))
311 .submenu_with_icon(None, target_label, window, cx, move |submenu, _, _| {
312 languages.iter().fold(
313 submenu
314 .check_side(Side::Right)
315 .max_h(px(LANGUAGE_LIST_HEIGHT))
316 .scrollable(true),
317 |submenu, language| {
318 let (app, code) = (target_app.clone(), language.code.clone());
319 submenu.item(
320 PopupMenuItem::new(language.name.clone())
321 .checked(language.code == target)
322 .on_click(move |_, _, cx| {
323 app.update(cx, |state, cx| state.set_translation_target(&code, cx));
324 }),
325 )
326 },
327 )
328 });
329 menu = menu.separator();
330 for (label, choice) in [
331 ("Ask me before translating", TranslationBehavior::Ask),
332 ("Auto-translate all messages", TranslationBehavior::Auto),
333 ("Never translate", TranslationBehavior::Never),
334 ] {
335 let app = app.clone();
336 menu = menu.item(
337 PopupMenuItem::new(label)
338 .checked(behavior == choice)
339 .on_click(move |_, _, cx| {
340 app.update(cx, |state, cx| state.set_translation_behavior(choice, cx));
341 }),
342 );
343 }
344 menu = menu
345 .separator()
346 .item(PopupMenuItem::label("Never translate messages in"));
347 if never.is_empty() {
348 return menu.item(PopupMenuItem::label("No languages"));
349 }
350 for (code, name) in never {
351 let app = app.clone();
352 menu = menu.item(
353 PopupMenuItem::element(move |_, _| {
354 h_flex()
355 .w(px(TOGGLE_LABEL_WIDTH))
356 .gap(px(12.))
357 .items_center()
358 .justify_between()
359 .child(div().flex_1().min_w_0().truncate().child(name.clone()))
360 .child(menu_icon(IconName::X))
361 })
362 .on_click(move |_, _, cx| {
363 app.update(cx, |state, cx| state.allow_translating_language(&code, cx));
364 }),
365 );
366 }
367 menu
368}
369
370fn section_toggle(
371 app: &Entity<AppState>,
372 section: ChatSection,
373 label: &'static str,
374 enabled: bool,
375) -> PopupMenuItem {
376 let app = app.clone();
377 PopupMenuItem::element(move |_, _| {
378 h_flex()
379 .w(px(TOGGLE_LABEL_WIDTH))
380 .gap(px(12.))
381 .items_center()
382 .justify_between()
383 .child(div().flex_1().min_w_0().truncate().child(label))
384 .child(switch(enabled))
385 })
386 .on_click(move |_, _, cx| {
387 app.update(cx, |state, cx| {
388 state.set_chat_section(section, !enabled, cx)
389 });
390 })
391}
392
393fn switch(enabled: bool) -> Div {
394 let thumb = div()
395 .size(px(SWITCH_THUMB))
396 .rounded_full()
397 .bg(theme::text_strong());
398 h_flex()
399 .w(px(SWITCH_WIDTH))
400 .h(px(SWITCH_HEIGHT))
401 .flex_none()
402 .p(px(SWITCH_PADDING))
403 .items_center()
404 .rounded_full()
405 .bg(if enabled {
406 theme::accent()
407 } else {
408 theme::badge_muted()
409 })
410 .when(enabled, |track| track.justify_end())
411 .child(thumb)
412}
413
414fn work_location_icon(kind: Option<WorkLocationKind>) -> gpui_kit::component::Icon {
262fn work_location_icon(kind: Option<WorkLocationKind>) -> gpui_kit::component::Icon {
415 menu_icon(match kind {
263 menu_icon(match kind {
416 Some(WorkLocationKind::Office) => IconName::Building2,
264 Some(WorkLocationKind::Office) => IconName::Building2,