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