BlueGit

ict rusty-teams

Files

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

call_extras.rs

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