BlueGit

ict rusty-teams

Files

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

call_extras.rs

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