BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / call_extras.rs

call_extras.rs

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