| 1 | use std::path::PathBuf; |
| 2 | |
| 3 | use calling::{CameraEffects, HoldState}; |
| 4 | use gpui_kit::assets::IconName; |
| 5 | use gpui_kit::component::button::{Button, ButtonVariants as _}; |
| 6 | use gpui_kit::component::dialog::DialogFooter; |
| 7 | use gpui_kit::component::menu::{PopupMenu, PopupMenuItem}; |
| 8 | use gpui_kit::component::switch::Switch; |
| 9 | use gpui_kit::component::tooltip::Tooltip; |
| 10 | use gpui_kit::component::{WindowExt as _, h_flex, v_flex}; |
| 11 | use gpui_kit::*; |
| 12 | |
| 13 | use super::call_organizer::pill; |
| 14 | use super::call_view::{BANNER_HEIGHT, MENU_WIDTH}; |
| 15 | use super::transfer_picker::{PickerMode, TransferPicker}; |
| 16 | use super::widgets::icon; |
| 17 | use crate::app_state::AppState; |
| 18 | use crate::call::{BackgroundPick, CallModel, RecordAction, RecordingChip}; |
| 19 | use crate::theme; |
| 20 | |
| 21 | const STAGE_RADIUS: f32 = 12.; |
| 22 | const THUMBNAIL_WIDTH: f32 = 64.; |
| 23 | const THUMBNAIL_HEIGHT: f32 = 36.; |
| 24 | const THUMBNAIL_GAP: f32 = 6.; |
| 25 | const MENU_PADDING: f32 = 24.; |
| 26 | const BACKDROP_OPACITY: f32 = 0.55; |
| 27 | const CARD_WIDTH: f32 = 420.; |
| 28 | |
| 29 | fn dark_text() -> Hsla { |
| 30 | hsla(0., 0., 0.08, 1.) |
| 31 | } |
| 32 | |
| 33 | pub fn recording_chip(model: &CallModel) -> Option<AnyElement> { |
| 34 | let chip = crate::call::recording_chip(model.recording, model.recording_audio_only, model.transcribing)?; |
| 35 | let color = match chip { |
| 36 | RecordingChip::Transcribing => theme::accent_text(), |
| 37 | RecordingChip::Recording | RecordingChip::RecordingAudio => theme::red(), |
| 38 | }; |
| 39 | Some( |
| 40 | h_flex() |
| 41 | .id("call-recording") |
| 42 | .flex_none() |
| 43 | .gap(px(6.)) |
| 44 | .items_center() |
| 45 | .text_size(px(13.)) |
| 46 | .font_weight(FontWeight::SEMIBOLD) |
| 47 | .text_color(color) |
| 48 | .child(div().size(px(9.)).rounded_full().bg(color)) |
| 49 | .child(chip.label()) |
| 50 | .into_any_element(), |
| 51 | ) |
| 52 | } |
| 53 | |
| 54 | pub fn return_button(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> { |
| 55 | model.breakout.as_ref().filter(|room| room.main.is_some())?; |
| 56 | let app = app.clone(); |
| 57 | Some( |
| 58 | Button::new("call-return-main") |
| 59 | .label("Return to main meeting") |
| 60 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.return_to_main_meeting(cx))) |
| 61 | .into_any_element(), |
| 62 | ) |
| 63 | } |
| 64 | |
| 65 | pub fn room_chip(model: &CallModel) -> Option<AnyElement> { |
| 66 | model.breakout.as_ref()?; |
| 67 | Some( |
| 68 | div() |
| 69 | .flex_none() |
| 70 | .text_size(px(13.)) |
| 71 | .text_color(theme::text_muted()) |
| 72 | .child("Breakout room") |
| 73 | .into_any_element(), |
| 74 | ) |
| 75 | } |
| 76 | |
| 77 | pub fn hold_panel(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> { |
| 78 | let (title, detail) = match model.hold { |
| 79 | HoldState::Active => return None, |
| 80 | HoldState::Local => ( |
| 81 | "On hold".to_owned(), |
| 82 | format!( |
| 83 | "{} cannot hear you and you cannot hear them.", |
| 84 | model.peer_name |
| 85 | ), |
| 86 | ), |
| 87 | HoldState::Remote => ( |
| 88 | "You're on hold".to_owned(), |
| 89 | format!("{} put the call on hold.", model.peer_name), |
| 90 | ), |
| 91 | }; |
| 92 | let resume = (model.hold == HoldState::Local).then(|| { |
| 93 | let app = app.clone(); |
| 94 | Button::new("call-resume") |
| 95 | .label("Resume") |
| 96 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_hold(cx))) |
| 97 | }); |
| 98 | Some( |
| 99 | v_flex() |
| 100 | .id("call-hold") |
| 101 | .flex_1() |
| 102 | .min_h_0() |
| 103 | .items_center() |
| 104 | .justify_center() |
| 105 | .gap(px(12.)) |
| 106 | .child( |
| 107 | div() |
| 108 | .size(px(96.)) |
| 109 | .flex() |
| 110 | .items_center() |
| 111 | .justify_center() |
| 112 | .rounded_full() |
| 113 | .bg(theme::surface_raised()) |
| 114 | .child(icon(IconName::Clock, 48., theme::text())), |
| 115 | ) |
| 116 | .child( |
| 117 | div() |
| 118 | .text_size(px(22.)) |
| 119 | .font_weight(FontWeight::SEMIBOLD) |
| 120 | .child(title), |
| 121 | ) |
| 122 | .child( |
| 123 | div() |
| 124 | .text_size(px(14.)) |
| 125 | .text_color(theme::text_muted()) |
| 126 | .child(detail), |
| 127 | ) |
| 128 | .children(resume) |
| 129 | .into_any_element(), |
| 130 | ) |
| 131 | } |
| 132 | |
| 133 | pub fn whiteboard_stage(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> { |
| 134 | let label = model.whiteboard_label()?; |
| 135 | let open = model.whiteboard_url().is_some().then(|| { |
| 136 | let app = app.clone(); |
| 137 | Button::new("call-whiteboard-open") |
| 138 | .label("Open in browser") |
| 139 | .icon(IconName::ExternalLink) |
| 140 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.open_call_whiteboard(cx))) |
| 141 | }); |
| 142 | Some( |
| 143 | v_flex() |
| 144 | .id("call-whiteboard-stage") |
| 145 | .flex_1() |
| 146 | .min_w_0() |
| 147 | .h_full() |
| 148 | .items_center() |
| 149 | .justify_center() |
| 150 | .gap(px(12.)) |
| 151 | .rounded(px(STAGE_RADIUS)) |
| 152 | .bg(hsla(0., 0., 0.04, 1.)) |
| 153 | .text_color(theme::white()) |
| 154 | .child(icon(IconName::Pencil, 56., theme::white())) |
| 155 | .child( |
| 156 | div() |
| 157 | .text_size(px(18.)) |
| 158 | .font_weight(FontWeight::SEMIBOLD) |
| 159 | .child(label), |
| 160 | ) |
| 161 | .children(open) |
| 162 | .into_any_element(), |
| 163 | ) |
| 164 | } |
| 165 | |
| 166 | pub fn consult_banner(app: &Entity<AppState>, state: &AppState) -> Option<AnyElement> { |
| 167 | let call = state.call.as_ref()?; |
| 168 | let consult = call.consult.as_ref()?; |
| 169 | state.held_call.as_ref()?; |
| 170 | let ready = consult.ready_to_transfer(&call.model); |
| 171 | let first_name = consult |
| 172 | .held_name |
| 173 | .split_whitespace() |
| 174 | .next() |
| 175 | .unwrap_or("call") |
| 176 | .to_owned(); |
| 177 | let (transfer_app, resume_app) = (app.clone(), app.clone()); |
| 178 | let transfer = pill("call-consult-transfer", "Transfer", true) |
| 179 | .debug_selector(|| "shell/islands/main/call-header/call-consult/transfer".into()); |
| 180 | let transfer = if ready { |
| 181 | transfer.on_click(move |_, _, cx| { |
| 182 | transfer_app.update(cx, |state, cx| state.transfer_consulted(cx)) |
| 183 | }) |
| 184 | } else { |
| 185 | transfer.opacity(0.5).cursor_default() |
| 186 | }; |
| 187 | let resume = pill("call-consult-resume", format!("Resume {first_name}"), false) |
| 188 | .debug_selector(|| "shell/islands/main/call-header/call-consult/resume".into()) |
| 189 | .on_click(move |_, _, cx| resume_app.update(cx, |state, cx| state.resume_held_call(cx))); |
| 190 | Some( |
| 191 | h_flex() |
| 192 | .id("call-consult-banner") |
| 193 | .debug_selector(|| "shell/islands/main/call-header/call-consult".into()) |
| 194 | .w_full() |
| 195 | .h(px(BANNER_HEIGHT)) |
| 196 | .flex_none() |
| 197 | .px(px(20.)) |
| 198 | .gap(px(12.)) |
| 199 | .items_center() |
| 200 | .justify_center() |
| 201 | .bg(theme::amber()) |
| 202 | .text_color(dark_text()) |
| 203 | .text_size(px(13.)) |
| 204 | .font_weight(FontWeight::SEMIBOLD) |
| 205 | .child(div().min_w_0().truncate().child(consult.banner_text())) |
| 206 | .child(transfer) |
| 207 | .child(resume) |
| 208 | .into_any_element(), |
| 209 | ) |
| 210 | } |
| 211 | |
| 212 | pub fn consent_overlay(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> { |
| 213 | if !model.consent_required { |
| 214 | return None; |
| 215 | } |
| 216 | let app = app.clone(); |
| 217 | Some( |
| 218 | div() |
| 219 | .id("call-consent-layer") |
| 220 | .absolute() |
| 221 | .top_0() |
| 222 | .left_0() |
| 223 | .size_full() |
| 224 | .flex() |
| 225 | .items_center() |
| 226 | .justify_center() |
| 227 | .child( |
| 228 | div() |
| 229 | .id("call-consent-backdrop") |
| 230 | .absolute() |
| 231 | .top_0() |
| 232 | .left_0() |
| 233 | .size_full() |
| 234 | .bg(black().opacity(BACKDROP_OPACITY)) |
| 235 | .occlude(), |
| 236 | ) |
| 237 | .child( |
| 238 | v_flex() |
| 239 | .id("call-consent-card") |
| 240 | .w(px(CARD_WIDTH)) |
| 241 | .max_w(relative(1.)) |
| 242 | .p(px(20.)) |
| 243 | .gap(px(12.)) |
| 244 | .rounded(px(10.)) |
| 245 | .bg(theme::popup()) |
| 246 | .text_color(theme::text()) |
| 247 | .occlude() |
| 248 | .child( |
| 249 | h_flex() |
| 250 | .gap(px(8.)) |
| 251 | .items_center() |
| 252 | .child(div().size(px(10.)).rounded_full().bg(theme::red())) |
| 253 | .child( |
| 254 | div() |
| 255 | .text_size(px(16.)) |
| 256 | .font_weight(FontWeight::SEMIBOLD) |
| 257 | .child("This meeting is being recorded"), |
| 258 | ), |
| 259 | ) |
| 260 | .child( |
| 261 | div() |
| 262 | .text_size(px(13.)) |
| 263 | .text_color(theme::text_muted()) |
| 264 | .child("Your microphone and camera stay off until you accept."), |
| 265 | ) |
| 266 | .child( |
| 267 | h_flex().w_full().justify_end().child( |
| 268 | Button::new("call-consent-ok") |
| 269 | .label("OK") |
| 270 | .on_click(move |_, _, cx| { |
| 271 | app.update(cx, |state, cx| state.accept_recording_notice(cx)) |
| 272 | }), |
| 273 | ), |
| 274 | ), |
| 275 | ) |
| 276 | .into_any_element(), |
| 277 | ) |
| 278 | } |
| 279 | |
| 280 | pub fn confirm_record_action(app: &Entity<AppState>, action: RecordAction, window: &mut Window, cx: &mut App) { |
| 281 | let Some(title) = action.confirm_title() else { |
| 282 | app.update(cx, |state, cx| state.run_call_record_action(action, cx)); |
| 283 | return; |
| 284 | }; |
| 285 | let app = app.clone(); |
| 286 | window.open_alert_dialog(cx, move |alert, _, _| { |
| 287 | let app = app.clone(); |
| 288 | let cancel = Button::new("recording-cancel").label("Cancel").on_click(|_, window, cx| window.close_dialog(cx)); |
| 289 | let stop = Button::new("recording-stop").label("Stop").danger().on_click(move |_, window, cx| { |
| 290 | app.update(cx, |state, cx| state.run_call_record_action(action, cx)); |
| 291 | window.close_dialog(cx); |
| 292 | }); |
| 293 | alert |
| 294 | .title(title) |
| 295 | .description("The file is saved to the organizer's OneDrive and the link arrives in the meeting chat.") |
| 296 | .footer(DialogFooter::new().child(cancel).child(stop)) |
| 297 | .on_ok(|_, _, _| false) |
| 298 | }); |
| 299 | } |
| 300 | |
| 301 | pub fn open_transfer_picker(app: &Entity<AppState>, window: &mut Window, cx: &mut App) { |
| 302 | let candidates = app.read(cx).transfer_candidates(); |
| 303 | let picker_app = app.clone(); |
| 304 | let picker = cx.new(|cx| TransferPicker::new(picker_app, candidates, PickerMode::Transfer, window, cx)); |
| 305 | app.update(cx, |state, cx| state.open_transfer_picker(picker, cx)); |
| 306 | } |
| 307 | |
| 308 | pub fn open_invite_picker(app: &Entity<AppState>, window: &mut Window, cx: &mut App) { |
| 309 | let candidates = app.read(cx).invite_candidates(); |
| 310 | let picker_app = app.clone(); |
| 311 | let picker = cx.new(|cx| TransferPicker::new(picker_app, candidates, PickerMode::Invite, window, cx)); |
| 312 | app.update(cx, |state, cx| state.open_invite_picker(picker, cx)); |
| 313 | } |
| 314 | |
| 315 | #[derive(Clone)] |
| 316 | pub struct CameraMenu { |
| 317 | pub pick: BackgroundPick, |
| 318 | pub images: Vec<(String, String, Option<PathBuf>)>, |
| 319 | pub customs: Vec<PathBuf>, |
| 320 | pub effects: CameraEffects, |
| 321 | } |
| 322 | |
| 323 | impl CameraMenu { |
| 324 | pub fn of(state: &AppState) -> Self { |
| 325 | let library = &state.call_backgrounds; |
| 326 | CameraMenu { |
| 327 | pick: state.call_background.clone(), |
| 328 | images: library |
| 329 | .shown() |
| 330 | .iter() |
| 331 | .map(|image| { |
| 332 | ( |
| 333 | image.id.clone(), |
| 334 | image.name.clone(), |
| 335 | library.thumbnail(image), |
| 336 | ) |
| 337 | }) |
| 338 | .collect(), |
| 339 | customs: library.customs.clone(), |
| 340 | effects: state.call_effects, |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | fn thumbnail( |
| 346 | app: &Entity<AppState>, |
| 347 | index: usize, |
| 348 | label: String, |
| 349 | path: Option<PathBuf>, |
| 350 | selected: bool, |
| 351 | pick: BackgroundPick, |
| 352 | ) -> AnyElement { |
| 353 | let app = app.clone(); |
| 354 | let tooltip = label.clone(); |
| 355 | div() |
| 356 | .id(("call-background", index)) |
| 357 | .w(px(THUMBNAIL_WIDTH)) |
| 358 | .h(px(THUMBNAIL_HEIGHT)) |
| 359 | .flex_none() |
| 360 | .overflow_hidden() |
| 361 | .rounded(px(6.)) |
| 362 | .border_2() |
| 363 | .border_color(if selected { |
| 364 | theme::accent() |
| 365 | } else { |
| 366 | transparent_black() |
| 367 | }) |
| 368 | .bg(theme::surface()) |
| 369 | .cursor_pointer() |
| 370 | .tooltip(move |window, cx| Tooltip::new(tooltip.clone()).build(window, cx)) |
| 371 | .child(match path { |
| 372 | Some(path) => img(path) |
| 373 | .size_full() |
| 374 | .object_fit(ObjectFit::Cover) |
| 375 | .into_any_element(), |
| 376 | None => div().size_full().into_any_element(), |
| 377 | }) |
| 378 | .on_click(move |_, _, cx| { |
| 379 | app.update(cx, |state, cx| state.set_call_background(pick.clone(), cx)) |
| 380 | }) |
| 381 | .into_any_element() |
| 382 | } |
| 383 | |
| 384 | fn effect_change( |
| 385 | app: &Entity<AppState>, |
| 386 | change: fn(&mut CameraEffects), |
| 387 | ) -> impl Fn(&ClickEvent, &mut Window, &mut App) + 'static { |
| 388 | let app = app.clone(); |
| 389 | move |_, _, cx| { |
| 390 | app.update(cx, |state, cx| { |
| 391 | let mut effects = state.call_effects; |
| 392 | change(&mut effects); |
| 393 | state.set_call_effects(effects, cx); |
| 394 | }) |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | fn effect_switch_item( |
| 399 | app: &Entity<AppState>, |
| 400 | id: &'static str, |
| 401 | label: &'static str, |
| 402 | on: bool, |
| 403 | change: fn(&mut CameraEffects), |
| 404 | ) -> PopupMenuItem { |
| 405 | PopupMenuItem::element(move |_, _| { |
| 406 | h_flex() |
| 407 | .id(id) |
| 408 | .w_full() |
| 409 | .gap(px(16.)) |
| 410 | .items_center() |
| 411 | .justify_between() |
| 412 | .child(label) |
| 413 | .child(Switch::new(id).checked(on)) |
| 414 | }) |
| 415 | .on_click(effect_change(app, change)) |
| 416 | } |
| 417 | |
| 418 | pub fn effect_items(popup: PopupMenu, app: &Entity<AppState>, effects: CameraEffects) -> PopupMenu { |
| 419 | popup |
| 420 | .separator() |
| 421 | .item(PopupMenuItem::label("Effects")) |
| 422 | .item(effect_switch_item( |
| 423 | app, |
| 424 | "call-effect-mirror", |
| 425 | "Mirror my video", |
| 426 | effects.mirror, |
| 427 | |effects| effects.mirror = !effects.mirror, |
| 428 | )) |
| 429 | .item(effect_switch_item( |
| 430 | app, |
| 431 | "call-effect-framing", |
| 432 | "Auto framing", |
| 433 | effects.auto_framing, |
| 434 | |effects| effects.auto_framing = !effects.auto_framing, |
| 435 | )) |
| 436 | .item(effect_switch_item( |
| 437 | app, |
| 438 | "call-effect-brightness", |
| 439 | "Adjust brightness", |
| 440 | effects.adjust_brightness, |
| 441 | |effects| effects.adjust_brightness = !effects.adjust_brightness, |
| 442 | )) |
| 443 | .item(effect_switch_item( |
| 444 | app, |
| 445 | "call-effect-soft-focus", |
| 446 | "Soft focus", |
| 447 | effects.soft_focus, |
| 448 | |effects| effects.soft_focus = !effects.soft_focus, |
| 449 | )) |
| 450 | } |
| 451 | |
| 452 | pub fn background_items(popup: PopupMenu, app: &Entity<AppState>, menu: &CameraMenu) -> PopupMenu { |
| 453 | let (none_app, blur_app, add_app, grid_app) = |
| 454 | (app.clone(), app.clone(), app.clone(), app.clone()); |
| 455 | let grid_menu = menu.clone(); |
| 456 | let mut popup = popup |
| 457 | .separator() |
| 458 | .item(PopupMenuItem::label("Background")) |
| 459 | .item( |
| 460 | PopupMenuItem::new("None") |
| 461 | .checked(menu.pick == BackgroundPick::None) |
| 462 | .on_click(move |_, _, cx| { |
| 463 | none_app.update(cx, |state, cx| { |
| 464 | state.set_call_background(BackgroundPick::None, cx) |
| 465 | }) |
| 466 | }), |
| 467 | ) |
| 468 | .item( |
| 469 | PopupMenuItem::new("Blur") |
| 470 | .checked(menu.pick.is_blur()) |
| 471 | .on_click(move |_, _, cx| { |
| 472 | blur_app.update(cx, |state, cx| { |
| 473 | state.set_call_background(BackgroundPick::Blur, cx) |
| 474 | }) |
| 475 | }), |
| 476 | ); |
| 477 | if !menu.images.is_empty() || !menu.customs.is_empty() { |
| 478 | popup = popup.item(PopupMenuItem::element(move |_, _| { |
| 479 | let defaults = grid_menu |
| 480 | .images |
| 481 | .iter() |
| 482 | .enumerate() |
| 483 | .map(|(index, (id, name, path))| { |
| 484 | let pick = BackgroundPick::Default(id.clone()); |
| 485 | thumbnail( |
| 486 | &grid_app, |
| 487 | index, |
| 488 | name.clone(), |
| 489 | path.clone(), |
| 490 | grid_menu.pick == pick, |
| 491 | pick, |
| 492 | ) |
| 493 | }); |
| 494 | let customs = grid_menu.customs.iter().enumerate().map(|(index, path)| { |
| 495 | let pick = BackgroundPick::Custom(path.clone()); |
| 496 | let name = path |
| 497 | .file_name() |
| 498 | .map_or_else(String::new, |name| name.to_string_lossy().into_owned()); |
| 499 | thumbnail( |
| 500 | &grid_app, |
| 501 | grid_menu.images.len() + index, |
| 502 | name, |
| 503 | Some(path.clone()), |
| 504 | grid_menu.pick == pick, |
| 505 | pick, |
| 506 | ) |
| 507 | }); |
| 508 | h_flex() |
| 509 | .w(px(MENU_WIDTH - MENU_PADDING)) |
| 510 | .flex_wrap() |
| 511 | .gap(px(THUMBNAIL_GAP)) |
| 512 | .children(defaults.chain(customs)) |
| 513 | })); |
| 514 | } |
| 515 | popup.item( |
| 516 | PopupMenuItem::new("Add image...") |
| 517 | .icon(IconName::Plus) |
| 518 | .on_click(move |_, _, cx| { |
| 519 | add_app.update(cx, |state, cx| state.add_call_background(cx)) |
| 520 | }), |
| 521 | ) |
| 522 | } |