BlueGit

ict rusty-teams

Files

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

call_extras.rs

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