| 1 | use std::path::PathBuf; |
| 2 | |
| 3 | use calling::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::tooltip::Tooltip; |
| 9 | use gpui_kit::component::{WindowExt as _, h_flex, v_flex}; |
| 10 | use gpui_kit::*; |
| 11 | |
| 12 | use super::call_organizer::pill; |
| 13 | use super::call_view::{BANNER_HEIGHT, MENU_WIDTH}; |
| 14 | use super::transfer_picker::TransferPicker; |
| 15 | use super::widgets::icon; |
| 16 | use crate::app_state::AppState; |
| 17 | use crate::call::{BackgroundPick, CallModel}; |
| 18 | use crate::theme; |
| 19 | |
| 20 | const STAGE_RADIUS: f32 = 12.; |
| 21 | const THUMBNAIL_WIDTH: f32 = 64.; |
| 22 | const THUMBNAIL_HEIGHT: f32 = 36.; |
| 23 | const THUMBNAIL_GAP: f32 = 6.; |
| 24 | const MENU_PADDING: f32 = 24.; |
| 25 | const BACKDROP_OPACITY: f32 = 0.55; |
| 26 | const CARD_WIDTH: f32 = 420.; |
| 27 | |
| 28 | fn dark_text() -> Hsla { |
| 29 | hsla(0., 0., 0.08, 1.) |
| 30 | } |
| 31 | |
| 32 | pub fn recording_chip(model: &CallModel) -> Option<AnyElement> { |
| 33 | model.recording.then(|| { |
| 34 | h_flex() |
| 35 | .id("call-recording") |
| 36 | .flex_none() |
| 37 | .gap(px(6.)) |
| 38 | .items_center() |
| 39 | .text_size(px(13.)) |
| 40 | .font_weight(FontWeight::SEMIBOLD) |
| 41 | .text_color(theme::red()) |
| 42 | .child(div().size(px(9.)).rounded_full().bg(theme::red())) |
| 43 | .child("Recording") |
| 44 | .into_any_element() |
| 45 | }) |
| 46 | } |
| 47 | |
| 48 | pub fn return_button(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> { |
| 49 | model.breakout.as_ref().filter(|room| room.main.is_some())?; |
| 50 | let app = app.clone(); |
| 51 | Some( |
| 52 | Button::new("call-return-main") |
| 53 | .label("Return to main meeting") |
| 54 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.return_to_main_meeting(cx))) |
| 55 | .into_any_element(), |
| 56 | ) |
| 57 | } |
| 58 | |
| 59 | pub fn room_chip(model: &CallModel) -> Option<AnyElement> { |
| 60 | model.breakout.as_ref()?; |
| 61 | Some(div().flex_none().text_size(px(13.)).text_color(theme::text_muted()).child("Breakout room").into_any_element()) |
| 62 | } |
| 63 | |
| 64 | pub fn hold_panel(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> { |
| 65 | let (title, detail) = match model.hold { |
| 66 | HoldState::Active => return None, |
| 67 | HoldState::Local => ("On hold".to_owned(), format!("{} cannot hear you and you cannot hear them.", model.peer_name)), |
| 68 | HoldState::Remote => ("You're on hold".to_owned(), format!("{} put the call on hold.", model.peer_name)), |
| 69 | }; |
| 70 | let resume = (model.hold == HoldState::Local).then(|| { |
| 71 | let app = app.clone(); |
| 72 | Button::new("call-resume").label("Resume").on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_hold(cx))) |
| 73 | }); |
| 74 | Some( |
| 75 | v_flex() |
| 76 | .id("call-hold") |
| 77 | .flex_1() |
| 78 | .min_h_0() |
| 79 | .items_center() |
| 80 | .justify_center() |
| 81 | .gap(px(12.)) |
| 82 | .child( |
| 83 | div() |
| 84 | .size(px(96.)) |
| 85 | .flex() |
| 86 | .items_center() |
| 87 | .justify_center() |
| 88 | .rounded_full() |
| 89 | .bg(theme::surface_raised()) |
| 90 | .child(icon(IconName::Clock, 48., theme::text())), |
| 91 | ) |
| 92 | .child(div().text_size(px(22.)).font_weight(FontWeight::SEMIBOLD).child(title)) |
| 93 | .child(div().text_size(px(14.)).text_color(theme::text_muted()).child(detail)) |
| 94 | .children(resume) |
| 95 | .into_any_element(), |
| 96 | ) |
| 97 | } |
| 98 | |
| 99 | pub fn whiteboard_stage(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> { |
| 100 | let label = model.whiteboard_label()?; |
| 101 | let open = model.whiteboard_url().is_some().then(|| { |
| 102 | let app = app.clone(); |
| 103 | Button::new("call-whiteboard-open") |
| 104 | .label("Open in browser") |
| 105 | .icon(IconName::ExternalLink) |
| 106 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.open_call_whiteboard(cx))) |
| 107 | }); |
| 108 | Some( |
| 109 | v_flex() |
| 110 | .id("call-whiteboard-stage") |
| 111 | .flex_1() |
| 112 | .min_w_0() |
| 113 | .h_full() |
| 114 | .items_center() |
| 115 | .justify_center() |
| 116 | .gap(px(12.)) |
| 117 | .rounded(px(STAGE_RADIUS)) |
| 118 | .bg(hsla(0., 0., 0.04, 1.)) |
| 119 | .text_color(theme::white()) |
| 120 | .child(icon(IconName::Pencil, 56., theme::white())) |
| 121 | .child(div().text_size(px(18.)).font_weight(FontWeight::SEMIBOLD).child(label)) |
| 122 | .children(open) |
| 123 | .into_any_element(), |
| 124 | ) |
| 125 | } |
| 126 | |
| 127 | pub fn consult_banner(app: &Entity<AppState>, state: &AppState) -> Option<AnyElement> { |
| 128 | let consult = state.call.as_ref()?.consult.as_ref()?; |
| 129 | let text = consult.status_text(); |
| 130 | let ready = consult.ready_to_transfer(); |
| 131 | let (transfer_app, cancel_app) = (app.clone(), app.clone()); |
| 132 | let transfer = pill("call-consult-transfer", "Transfer now", true); |
| 133 | let transfer = if ready { |
| 134 | transfer.on_click(move |_, _, cx| transfer_app.update(cx, |state, cx| state.transfer_consulted(cx))) |
| 135 | } else { |
| 136 | transfer.opacity(0.5).cursor_default() |
| 137 | }; |
| 138 | Some( |
| 139 | h_flex() |
| 140 | .id("call-consult-banner") |
| 141 | .w_full() |
| 142 | .h(px(BANNER_HEIGHT)) |
| 143 | .flex_none() |
| 144 | .px(px(20.)) |
| 145 | .gap(px(12.)) |
| 146 | .items_center() |
| 147 | .justify_center() |
| 148 | .bg(theme::amber()) |
| 149 | .text_color(dark_text()) |
| 150 | .text_size(px(13.)) |
| 151 | .font_weight(FontWeight::SEMIBOLD) |
| 152 | .child(text) |
| 153 | .child(transfer) |
| 154 | .child(pill("call-consult-cancel", "Cancel", false).on_click(move |_, _, cx| cancel_app.update(cx, |state, cx| state.cancel_consult(cx)))) |
| 155 | .into_any_element(), |
| 156 | ) |
| 157 | } |
| 158 | |
| 159 | pub fn consent_overlay(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> { |
| 160 | if !model.consent_required { |
| 161 | return None; |
| 162 | } |
| 163 | let app = app.clone(); |
| 164 | Some( |
| 165 | div() |
| 166 | .id("call-consent-layer") |
| 167 | .absolute() |
| 168 | .top_0() |
| 169 | .left_0() |
| 170 | .size_full() |
| 171 | .flex() |
| 172 | .items_center() |
| 173 | .justify_center() |
| 174 | .child(div().id("call-consent-backdrop").absolute().top_0().left_0().size_full().bg(black().opacity(BACKDROP_OPACITY)).occlude()) |
| 175 | .child( |
| 176 | v_flex() |
| 177 | .id("call-consent-card") |
| 178 | .w(px(CARD_WIDTH)) |
| 179 | .max_w(relative(1.)) |
| 180 | .p(px(20.)) |
| 181 | .gap(px(12.)) |
| 182 | .rounded(px(10.)) |
| 183 | .bg(theme::popup()) |
| 184 | .text_color(theme::text()) |
| 185 | .occlude() |
| 186 | .child( |
| 187 | h_flex() |
| 188 | .gap(px(8.)) |
| 189 | .items_center() |
| 190 | .child(div().size(px(10.)).rounded_full().bg(theme::red())) |
| 191 | .child(div().text_size(px(16.)).font_weight(FontWeight::SEMIBOLD).child("This meeting is being recorded")), |
| 192 | ) |
| 193 | .child( |
| 194 | div() |
| 195 | .text_size(px(13.)) |
| 196 | .text_color(theme::text_muted()) |
| 197 | .child("Your microphone and camera stay off until you accept."), |
| 198 | ) |
| 199 | .child( |
| 200 | h_flex().w_full().justify_end().child( |
| 201 | Button::new("call-consent-ok") |
| 202 | .label("OK") |
| 203 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.accept_recording_notice(cx))), |
| 204 | ), |
| 205 | ), |
| 206 | ) |
| 207 | .into_any_element(), |
| 208 | ) |
| 209 | } |
| 210 | |
| 211 | pub fn confirm_stop_recording(app: &Entity<AppState>, window: &mut Window, cx: &mut App) { |
| 212 | let app = app.clone(); |
| 213 | window.open_alert_dialog(cx, move |alert, _, _| { |
| 214 | let app = app.clone(); |
| 215 | let cancel = Button::new("recording-cancel").label("Cancel").on_click(|_, window, cx| window.close_dialog(cx)); |
| 216 | let stop = Button::new("recording-stop").label("Stop").danger().on_click(move |_, window, cx| { |
| 217 | app.update(cx, |state, cx| state.set_call_recording(false, cx)); |
| 218 | window.close_dialog(cx); |
| 219 | }); |
| 220 | alert |
| 221 | .title("Stop recording and transcription?") |
| 222 | .description("The recording is saved to the organizer's OneDrive and the link arrives in the meeting chat.") |
| 223 | .footer(DialogFooter::new().child(cancel).child(stop)) |
| 224 | .on_ok(|_, _, _| false) |
| 225 | }); |
| 226 | } |
| 227 | |
| 228 | pub fn open_transfer_picker(app: &Entity<AppState>, window: &mut Window, cx: &mut App) { |
| 229 | let candidates = app.read(cx).transfer_candidates(); |
| 230 | let picker_app = app.clone(); |
| 231 | let picker = cx.new(|cx| TransferPicker::new(picker_app, candidates, window, cx)); |
| 232 | app.update(cx, |state, cx| state.open_transfer_picker(picker, cx)); |
| 233 | } |
| 234 | |
| 235 | #[derive(Clone)] |
| 236 | pub struct BackgroundMenu { |
| 237 | pub pick: BackgroundPick, |
| 238 | pub images: Vec<(String, String, Option<PathBuf>)>, |
| 239 | pub customs: Vec<PathBuf>, |
| 240 | } |
| 241 | |
| 242 | impl BackgroundMenu { |
| 243 | pub fn of(state: &AppState) -> Self { |
| 244 | let library = &state.call_backgrounds; |
| 245 | BackgroundMenu { |
| 246 | pick: state.call_background.clone(), |
| 247 | images: library.shown().iter().map(|image| (image.id.clone(), image.name.clone(), library.thumbnail(image))).collect(), |
| 248 | customs: library.customs.clone(), |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | fn thumbnail(app: &Entity<AppState>, index: usize, label: String, path: Option<PathBuf>, selected: bool, pick: BackgroundPick) -> AnyElement { |
| 254 | let app = app.clone(); |
| 255 | let tooltip = label.clone(); |
| 256 | div() |
| 257 | .id(("call-background", index)) |
| 258 | .w(px(THUMBNAIL_WIDTH)) |
| 259 | .h(px(THUMBNAIL_HEIGHT)) |
| 260 | .flex_none() |
| 261 | .overflow_hidden() |
| 262 | .rounded(px(6.)) |
| 263 | .border_2() |
| 264 | .border_color(if selected { theme::accent() } else { transparent_black() }) |
| 265 | .bg(theme::surface()) |
| 266 | .cursor_pointer() |
| 267 | .tooltip(move |window, cx| Tooltip::new(tooltip.clone()).build(window, cx)) |
| 268 | .child(match path { |
| 269 | Some(path) => img(path).size_full().object_fit(ObjectFit::Cover).into_any_element(), |
| 270 | None => div().size_full().into_any_element(), |
| 271 | }) |
| 272 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_background(pick.clone(), cx))) |
| 273 | .into_any_element() |
| 274 | } |
| 275 | |
| 276 | pub fn background_items(popup: PopupMenu, app: &Entity<AppState>, menu: &BackgroundMenu) -> PopupMenu { |
| 277 | let (none_app, blur_app, add_app, grid_app) = (app.clone(), app.clone(), app.clone(), app.clone()); |
| 278 | let grid_menu = menu.clone(); |
| 279 | let mut popup = popup |
| 280 | .separator() |
| 281 | .item(PopupMenuItem::label("Background")) |
| 282 | .item(PopupMenuItem::new("None").checked(menu.pick == BackgroundPick::None).on_click(move |_, _, cx| none_app.update(cx, |state, cx| state.set_call_background(BackgroundPick::None, cx)))) |
| 283 | .item(PopupMenuItem::new("Blur").checked(menu.pick.is_blur()).on_click(move |_, _, cx| blur_app.update(cx, |state, cx| state.set_call_background(BackgroundPick::Blur, cx)))); |
| 284 | if !menu.images.is_empty() || !menu.customs.is_empty() { |
| 285 | popup = popup.item(PopupMenuItem::element(move |_, _| { |
| 286 | let defaults = grid_menu.images.iter().enumerate().map(|(index, (id, name, path))| { |
| 287 | let pick = BackgroundPick::Default(id.clone()); |
| 288 | thumbnail(&grid_app, index, name.clone(), path.clone(), grid_menu.pick == pick, pick) |
| 289 | }); |
| 290 | let customs = grid_menu.customs.iter().enumerate().map(|(index, path)| { |
| 291 | let pick = BackgroundPick::Custom(path.clone()); |
| 292 | let name = path.file_name().map_or_else(String::new, |name| name.to_string_lossy().into_owned()); |
| 293 | thumbnail(&grid_app, grid_menu.images.len() + index, name, Some(path.clone()), grid_menu.pick == pick, pick) |
| 294 | }); |
| 295 | h_flex().w(px(MENU_WIDTH - MENU_PADDING)).flex_wrap().gap(px(THUMBNAIL_GAP)).children(defaults.chain(customs)) |
| 296 | })); |
| 297 | } |
| 298 | popup.item( |
| 299 | PopupMenuItem::new("Add image...") |
| 300 | .icon(IconName::Plus) |
| 301 | .on_click(move |_, _, cx| add_app.update(cx, |state, cx| state.add_call_background(cx))), |
| 302 | ) |
| 303 | } |