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