BlueGit

ict rusty-teams

Files

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

call_extras.rs

039de50c History
call_extras.rs 18.4 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 pub quality: calling::VideoQuality,
323}
324
325impl CameraMenu {
326 pub fn of(state: &AppState) -> Self {
327 let library = &state.call_backgrounds;
328 CameraMenu {
329 pick: state.call_background.clone(),
330 images: library
331 .shown()
332 .iter()
333 .map(|image| {
334 (
335 image.id.clone(),
336 image.name.clone(),
337 library.thumbnail(image),
338 )
339 })
340 .collect(),
341 customs: library.customs.clone(),
342 effects: state.call_effects,
343 quality: state.call_video_quality,
344 }
345 }
346}
347
348pub fn quality_items(
349 popup: PopupMenu,
350 app: &Entity<AppState>,
351 current: calling::VideoQuality,
352) -> PopupMenu {
353 let choices = [
354 (calling::VideoQuality::Auto, "Auto"),
355 (calling::VideoQuality::P720, "720p"),
356 (calling::VideoQuality::P1080, "1080p"),
357 ];
358 let mut popup = popup.separator().item(PopupMenuItem::label("Video quality"));
359 for (quality, label) in choices {
360 let app = app.clone();
361 popup = popup.item(
362 PopupMenuItem::new(label)
363 .checked(current == quality)
364 .on_click(move |_, _, cx| {
365 app.update(cx, |state, cx| state.set_call_video_quality(quality, cx))
366 }),
367 );
368 }
369 popup
370}
371
372fn thumbnail(
373 app: &Entity<AppState>,
374 index: usize,
375 label: String,
376 path: Option<PathBuf>,
377 selected: bool,
378 pick: BackgroundPick,
379) -> AnyElement {
380 let app = app.clone();
381 let tooltip = label.clone();
382 div()
383 .id(("call-background", index))
384 .w(px(THUMBNAIL_WIDTH))
385 .h(px(THUMBNAIL_HEIGHT))
386 .flex_none()
387 .overflow_hidden()
388 .rounded(px(6.))
389 .border_2()
390 .border_color(if selected {
391 theme::accent()
392 } else {
393 transparent_black()
394 })
395 .bg(theme::surface())
396 .cursor_pointer()
397 .tooltip(move |window, cx| Tooltip::new(tooltip.clone()).build(window, cx))
398 .child(match path {
399 Some(path) => img(bounded(path))
400 .size_full()
401 .object_fit(ObjectFit::Cover)
402 .into_any_element(),
403 None => div().size_full().into_any_element(),
404 })
405 .on_click(move |_, _, cx| {
406 app.update(cx, |state, cx| state.set_call_background(pick.clone(), cx))
407 })
408 .into_any_element()
409}
410
411fn effect_change(
412 app: &Entity<AppState>,
413 change: fn(&mut CameraEffects),
414) -> impl Fn(&ClickEvent, &mut Window, &mut App) + 'static {
415 let app = app.clone();
416 move |_, _, cx| {
417 app.update(cx, |state, cx| {
418 let mut effects = state.call_effects;
419 change(&mut effects);
420 state.set_call_effects(effects, cx);
421 })
422 }
423}
424
425fn effect_switch_item(
426 app: &Entity<AppState>,
427 id: &'static str,
428 label: &'static str,
429 on: bool,
430 change: fn(&mut CameraEffects),
431) -> PopupMenuItem {
432 PopupMenuItem::element(move |_, _| {
433 h_flex()
434 .id(id)
435 .w_full()
436 .gap(px(16.))
437 .items_center()
438 .justify_between()
439 .child(label)
440 .child(Switch::new(id).checked(on))
441 })
442 .on_click(effect_change(app, change))
443}
444
445pub fn effect_items(popup: PopupMenu, app: &Entity<AppState>, effects: CameraEffects) -> PopupMenu {
446 popup
447 .separator()
448 .item(PopupMenuItem::label("Effects"))
449 .item(effect_switch_item(
450 app,
451 "call-effect-mirror",
452 "Mirror my video",
453 effects.mirror,
454 |effects| effects.mirror = !effects.mirror,
455 ))
456 .item(effect_switch_item(
457 app,
458 "call-effect-framing",
459 "Auto framing",
460 effects.auto_framing,
461 |effects| effects.auto_framing = !effects.auto_framing,
462 ))
463 .item(effect_switch_item(
464 app,
465 "call-effect-brightness",
466 "Adjust brightness",
467 effects.adjust_brightness,
468 |effects| effects.adjust_brightness = !effects.adjust_brightness,
469 ))
470 .item(effect_switch_item(
471 app,
472 "call-effect-soft-focus",
473 "Soft focus",
474 effects.soft_focus,
475 |effects| effects.soft_focus = !effects.soft_focus,
476 ))
477}
478
479pub fn background_items(popup: PopupMenu, app: &Entity<AppState>, menu: &CameraMenu) -> PopupMenu {
480 let (none_app, blur_app, add_app, grid_app) =
481 (app.clone(), app.clone(), app.clone(), app.clone());
482 let grid_menu = menu.clone();
483 let mut popup = popup
484 .separator()
485 .item(PopupMenuItem::label("Background"))
486 .item(
487 PopupMenuItem::new("None")
488 .checked(menu.pick == BackgroundPick::None)
489 .on_click(move |_, _, cx| {
490 none_app.update(cx, |state, cx| {
491 state.set_call_background(BackgroundPick::None, cx)
492 })
493 }),
494 )
495 .item(
496 PopupMenuItem::new("Blur")
497 .checked(menu.pick.is_blur())
498 .on_click(move |_, _, cx| {
499 blur_app.update(cx, |state, cx| {
500 state.set_call_background(BackgroundPick::Blur, cx)
501 })
502 }),
503 );
504 if !menu.images.is_empty() || !menu.customs.is_empty() {
505 popup = popup.item(PopupMenuItem::element(move |_, _| {
506 let defaults = grid_menu
507 .images
508 .iter()
509 .enumerate()
510 .map(|(index, (id, name, path))| {
511 let pick = BackgroundPick::Default(id.clone());
512 thumbnail(
513 &grid_app,
514 index,
515 name.clone(),
516 path.clone(),
517 grid_menu.pick == pick,
518 pick,
519 )
520 });
521 let customs = grid_menu.customs.iter().enumerate().map(|(index, path)| {
522 let pick = BackgroundPick::Custom(path.clone());
523 let name = path
524 .file_name()
525 .map_or_else(String::new, |name| name.to_string_lossy().into_owned());
526 thumbnail(
527 &grid_app,
528 grid_menu.images.len() + index,
529 name,
530 Some(path.clone()),
531 grid_menu.pick == pick,
532 pick,
533 )
534 });
535 h_flex()
536 .w(px(MENU_WIDTH - MENU_PADDING))
537 .flex_wrap()
538 .gap(px(THUMBNAIL_GAP))
539 .children(defaults.chain(customs))
540 }));
541 }
542 popup.item(
543 PopupMenuItem::new("Add image...")
544 .icon(IconName::Plus)
545 .on_click(move |_, _, cx| {
546 add_app.update(cx, |state, cx| state.add_call_background(cx))
547 }),
548 )
549}