BlueGit

ict rusty-teams

Files

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

call_extras.rs

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