BlueGit

ict rusty-teams

Files

rusty-teams / crates / calling / src / screen.rs

screen.rs

screen.rs 22.7 KiB Download Raw
1use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
2use std::sync::{Arc, Mutex};
3use std::time::{Duration, Instant};
4
5use libwebrtc::desktop_capturer::{
6 CaptureError, CaptureSource, DesktopCaptureSourceType, DesktopCapturer, DesktopCapturerOptions,
7 PortalPickerEvent,
8};
9use libwebrtc::native::yuv_helper::{argb_scale, argb_to_i420};
10use libwebrtc::video_frame::I420Buffer;
11
12use crate::capture::Capture;
13use crate::error::{Error, Result};
14use crate::video_frame::VideoPicture;
15use crate::win_timer::HighResSleep;
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum ShareKind {
19 Screen,
20 Window,
21}
22
23impl ShareKind {
24 fn source_type(self) -> DesktopCaptureSourceType {
25 match self {
26 ShareKind::Screen => DesktopCaptureSourceType::Screen,
27 ShareKind::Window => DesktopCaptureSourceType::Window,
28 }
29 }
30}
31
32#[derive(Debug, Clone, PartialEq, Eq)]
33pub struct ShareSource {
34 pub id: u64,
35 pub kind: ShareKind,
36 pub title: String,
37}
38
39impl ShareSource {
40 pub fn label(&self) -> String {
41 match (self.kind, self.title.trim()) {
42 (ShareKind::Screen, "") => "Entire screen".to_owned(),
43 (_, "") => "Window".to_owned(),
44 (_, title) => title.to_owned(),
45 }
46 }
47}
48
49fn capturer(kind: ShareKind) -> Option<DesktopCapturer> {
50 let mut options = DesktopCapturerOptions::new(kind.source_type());
51 options.set_include_cursor(true);
52 DesktopCapturer::new(options)
53}
54
55fn sources_of(kind: ShareKind) -> Vec<(ShareSource, CaptureSource)> {
56 let Some(capturer) = capturer(kind) else {
57 return Vec::new();
58 };
59 capturer
60 .get_source_list()
61 .into_iter()
62 .map(|source| {
63 (
64 ShareSource {
65 id: source.id(),
66 kind,
67 title: source.title(),
68 },
69 source,
70 )
71 })
72 .collect()
73}
74
75pub fn list_share_sources() -> Vec<ShareSource> {
76 [ShareKind::Screen, ShareKind::Window]
77 .into_iter()
78 .flat_map(|kind| sources_of(kind).into_iter().map(|(source, _)| source))
79 .collect()
80}
81
82const THUMBNAIL_ATTEMPTS: u32 = 5;
83const SOURCE_GONE_AFTER: Duration = Duration::from_secs(3);
84const THUMBNAIL_RETRY: Duration = Duration::from_millis(40);
85
86pub fn share_thumbnail(
87 wanted: &ShareSource,
88 max_width: u32,
89 max_height: u32,
90) -> Option<VideoPicture> {
91 let source = sources_of(wanted.kind)
92 .into_iter()
93 .find(|(source, _)| source.id == wanted.id)
94 .map(|(_, raw)| raw)?;
95 let mut capturer = capturer(wanted.kind)?;
96 let captured: Arc<Mutex<Option<VideoPicture>>> = Arc::default();
97 let sink = captured.clone();
98 capturer.start_capture(Some(source), move |result| {
99 let Ok(frame) = result else { return };
100 let (width, height) = (frame.width().max(0) as u32, frame.height().max(0) as u32);
101 if let Some(picture) = scaled_bgra(
102 frame.data(),
103 width,
104 height,
105 frame.stride(),
106 max_width,
107 max_height,
108 ) && let Ok(mut slot) = sink.lock()
109 {
110 *slot = Some(picture);
111 }
112 });
113 for _ in 0..THUMBNAIL_ATTEMPTS {
114 pump_messages();
115 capturer.capture_frame();
116 if let Some(picture) = captured.lock().ok().and_then(|mut slot| slot.take()) {
117 return Some(picture);
118 }
119 std::thread::sleep(THUMBNAIL_RETRY);
120 }
121 None
122}
123
124// Windows Graphics Capture hands frames to a DispatcherQueue on this thread; without a pump none arrive.
125#[cfg(windows)]
126fn pump_messages() {
127 use windows::Win32::UI::WindowsAndMessaging::{
128 DispatchMessageW, MSG, PM_REMOVE, PeekMessageW, TranslateMessage,
129 };
130 let mut message = MSG::default();
131 unsafe {
132 while PeekMessageW(&mut message, None, 0, 0, PM_REMOVE).as_bool() {
133 let _ = TranslateMessage(&message);
134 let _ = DispatchMessageW(&message);
135 }
136 }
137}
138
139#[cfg(not(windows))]
140fn pump_messages() {}
141
142fn scaled_bgra(
143 bytes: &[u8],
144 width: u32,
145 height: u32,
146 stride: u32,
147 max_width: u32,
148 max_height: u32,
149) -> Option<VideoPicture> {
150 if width == 0
151 || height == 0
152 || (stride as usize) < width as usize * 4
153 || bytes.len() < stride as usize * height as usize
154 {
155 return None;
156 }
157 let scale = (max_width as f32 / width as f32)
158 .min(max_height as f32 / height as f32)
159 .min(1.);
160 let (target_width, target_height) = (
161 ((width as f32 * scale) as u32).max(1),
162 ((height as f32 * scale) as u32).max(1),
163 );
164 let mut bgra = Vec::with_capacity(target_width as usize * target_height as usize * 4);
165 for row in 0..target_height {
166 let source_row = (row as u64 * height as u64 / target_height as u64) as usize;
167 for column in 0..target_width {
168 let source_column = (column as u64 * width as u64 / target_width as u64) as usize;
169 let offset = source_row * stride as usize + source_column * 4;
170 bgra.extend_from_slice(&[bytes[offset], bytes[offset + 1], bytes[offset + 2], u8::MAX]);
171 }
172 }
173 Some(VideoPicture {
174 width: target_width,
175 height: target_height,
176 bgra,
177 })
178}
179
180const SHARE_SEND_MAX_FS: u32 = 8160;
181const MACROBLOCK: u32 = 16;
182
183fn macroblocks(width: u32, height: u32) -> u32 {
184 width.div_ceil(MACROBLOCK) * height.div_ceil(MACROBLOCK)
185}
186
187fn even(value: u32) -> u32 {
188 value & !1
189}
190
191fn buffer_covers(bytes: &[u8], width: u32, height: u32, stride: u32) -> bool {
192 width >= 2
193 && height >= 2
194 && stride as usize >= width as usize * 4
195 && bytes.len() >= stride as usize * height as usize
196}
197
198pub(crate) fn fit_share_size(width: u32, height: u32, max_fs: u32) -> (u32, u32) {
199 let (width, height) = (even(width), even(height));
200 if width < 2 || height < 2 || max_fs == 0 || macroblocks(width, height) <= max_fs {
201 return (width, height);
202 }
203 let mut scale = (f64::from(macroblocks(width, height)) / f64::from(max_fs)).sqrt();
204 let mut target_width = even((f64::from(width) / scale) as u32).max(2);
205 let mut target_height = even((f64::from(height) / scale) as u32).max(2);
206 while macroblocks(target_width, target_height) > max_fs && target_width > 2 && target_height > 2
207 {
208 scale *= 1.05;
209 target_width = even((f64::from(width) / scale) as u32).max(2);
210 target_height = even((f64::from(height) / scale) as u32).max(2);
211 }
212 (target_width, target_height)
213}
214
215fn scale_bgra_to(
216 bytes: &[u8],
217 width: u32,
218 height: u32,
219 stride: u32,
220 target_width: u32,
221 target_height: u32,
222) -> Vec<u8> {
223 let mut scaled = vec![0u8; target_width as usize * target_height as usize * 4];
224 argb_scale(
225 bytes,
226 stride,
227 width as i32,
228 height as i32,
229 &mut scaled,
230 target_width * 4,
231 target_width as i32,
232 target_height as i32,
233 );
234 scaled
235}
236
237fn share_frame(bytes: &[u8], width: u32, height: u32, stride: u32) -> Option<I420Buffer> {
238 let (width, height) = (even(width), even(height));
239 if !buffer_covers(bytes, width, height, stride) {
240 return None;
241 }
242 let (target_width, target_height) = fit_share_size(width, height, SHARE_SEND_MAX_FS);
243 if target_width == width && target_height == height {
244 return Some(i420_from_bgra(bytes, width, height, stride));
245 }
246 let scaled = scale_bgra_to(bytes, width, height, stride, target_width, target_height);
247 Some(i420_from_bgra(
248 &scaled,
249 target_width,
250 target_height,
251 target_width * 4,
252 ))
253}
254
255fn i420_from_bgra(bytes: &[u8], width: u32, height: u32, stride: u32) -> I420Buffer {
256 let mut buffer = I420Buffer::new(width, height);
257 let (stride_y, stride_u, stride_v) = buffer.strides();
258 let (plane_y, plane_u, plane_v) = buffer.data_mut();
259 argb_to_i420(
260 bytes,
261 stride,
262 plane_y,
263 stride_y,
264 plane_u,
265 stride_u,
266 plane_v,
267 stride_v,
268 width as i32,
269 height as i32,
270 );
271 buffer
272}
273
274pub fn start_screen_capture(
275 wanted: ShareSource,
276 fps: Arc<AtomicU32>,
277 mut deliver: impl FnMut(I420Buffer) + Send + 'static,
278 failed: impl FnOnce(String) + Send + 'static,
279) -> Result<Capture> {
280 if current_share_picker() == SharePicker::Portal {
281 return start_portal_capture(wanted.kind, fps, deliver, move |follow| {
282 if let PortalFollowUp::Notice(text) = follow {
283 failed(text.to_owned());
284 }
285 });
286 }
287 Capture::spawn_thread("screen-capture", move |stop| {
288 let Some(source) = sources_of(wanted.kind)
289 .into_iter()
290 .find(|(source, _)| source.id == wanted.id)
291 .map(|(_, raw)| raw)
292 else {
293 return failed("the shared source is gone".to_owned());
294 };
295 let Some(mut capturer) = capturer(wanted.kind) else {
296 return failed("screen capture is not available".to_owned());
297 };
298 let gone_since: Arc<Mutex<Option<Instant>>> = Arc::default();
299 let gone_mark = gone_since.clone();
300 capturer.start_capture(Some(source), move |result| {
301 let frame = match result {
302 Ok(frame) => frame,
303 Err(error) => {
304 if matches!(error, CaptureError::Permanent)
305 && let Ok(mut since) = gone_mark.lock()
306 {
307 since.get_or_insert_with(Instant::now);
308 }
309 return;
310 }
311 };
312 if let Ok(mut since) = gone_mark.lock() {
313 *since = None;
314 }
315 let (width, height) = (frame.width() as u32 & !1, frame.height() as u32 & !1);
316 if let Some(picture) = share_frame(frame.data(), width, height, frame.stride()) {
317 deliver(picture);
318 }
319 });
320 let sleeper = HighResSleep::new();
321 while !stop.load(Ordering::SeqCst) {
322 let started = Instant::now();
323 let gone = gone_since
324 .lock()
325 .is_ok_and(|since| since.is_some_and(|since| since.elapsed() >= SOURCE_GONE_AFTER));
326 if gone {
327 return failed("the shared source is gone".to_owned());
328 }
329 pump_messages();
330 capturer.capture_frame();
331 let period = Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1);
332 sleeper.sleep_until(started + period);
333 }
334 })
335 .map_err(|error| Error::Webrtc(format!("screen thread: {error}")))
336}
337
338/// Where the share menu gets its sources. Wayland and macOS use a system dialog.
339#[derive(Debug, Clone, Copy, PartialEq, Eq)]
340pub enum SharePicker {
341 List,
342 Portal,
343}
344
345pub fn share_picker_for(wayland_display: Option<&str>) -> SharePicker {
346 share_picker_for_host(cfg!(target_os = "macos"), wayland_display)
347}
348
349pub fn share_picker_for_host(macos: bool, wayland_display: Option<&str>) -> SharePicker {
350 if macos {
351 return SharePicker::Portal;
352 }
353 match wayland_display {
354 Some(value) if !value.is_empty() => SharePicker::Portal,
355 _ => SharePicker::List,
356 }
357}
358
359pub fn current_share_picker() -> SharePicker {
360 share_picker_for(std::env::var("WAYLAND_DISPLAY").ok().as_deref())
361}
362
363/// Portal menus must not enumerate or thumbnail sources. That would open the dialog early.
364pub fn share_sources_for_menu(picker: SharePicker, sources: Vec<ShareSource>) -> Vec<ShareSource> {
365 match picker {
366 SharePicker::Portal => Vec::new(),
367 SharePicker::List => sources,
368 }
369}
370
371pub use crate::notices::PORTAL_UNAVAILABLE_NOTICE;
372
373#[derive(Debug, Clone, PartialEq, Eq)]
374pub enum PortalFollowUp {
375 Share(ShareSource),
376 Quiet,
377 Notice(&'static str),
378}
379
380pub fn portal_follow_up(event: PortalPickerEvent, source: Option<ShareSource>) -> PortalFollowUp {
381 match event {
382 PortalPickerEvent::Selected => match source {
383 Some(source) => PortalFollowUp::Share(source),
384 None => PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE),
385 },
386 PortalPickerEvent::Cancelled => PortalFollowUp::Quiet,
387 PortalPickerEvent::Failed => PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE),
388 }
389}
390
391/// What a frame result says about a system picker without a delegated
392/// controller (macOS). Frames start once a source is picked. A cancel, or a
393/// picker that fails to start, turns into a permanent error.
394fn picker_event_from_frame<T>(
395 result: &std::result::Result<T, CaptureError>,
396) -> Option<PortalPickerEvent> {
397 match result {
398 Ok(_) => Some(PortalPickerEvent::Selected),
399 Err(CaptureError::Permanent) => Some(PortalPickerEvent::Cancelled),
400 Err(CaptureError::Temporary) => None,
401 }
402}
403
404pub(crate) fn start_portal_capture(
405 kind: ShareKind,
406 fps: Arc<AtomicU32>,
407 mut deliver: impl FnMut(I420Buffer) + Send + 'static,
408 outcome: impl FnOnce(PortalFollowUp) + Send + 'static,
409) -> Result<Capture> {
410 Capture::spawn_thread("portal-share", move |stop| {
411 libwebrtc::desktop_capturer::ensure_shared_glib_loop();
412 let Some(mut capturer) = capturer(kind) else {
413 outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));
414 return;
415 };
416 // The Wayland portal reports the pick through a delegated picker. The
417 // macOS system picker has none: it opens in `start_capture` and the
418 // outcome shows in the frame results.
419 let delegated = capturer.has_delegated_picker();
420 if !delegated && !cfg!(target_os = "macos") {
421 outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));
422 return;
423 }
424 let (sender, receiver) = std::sync::mpsc::channel();
425 let frame_events = (!delegated).then(|| sender.clone());
426 let selected = Arc::new(AtomicBool::new(false));
427 let gate = selected.clone();
428 capturer.start_capture(None, move |result| {
429 if !gate.load(Ordering::SeqCst) {
430 let Some(events) = &frame_events else { return };
431 let Some(event) = picker_event_from_frame(&result) else {
432 return;
433 };
434 let _ = events.send(event);
435 if event != PortalPickerEvent::Selected {
436 return;
437 }
438 gate.store(true, Ordering::SeqCst);
439 }
440 let Ok(frame) = result else { return };
441 let (width, height) = (frame.width() as u32 & !1, frame.height() as u32 & !1);
442 if let Some(picture) = share_frame(frame.data(), width, height, frame.stride()) {
443 deliver(picture);
444 }
445 });
446 if delegated {
447 capturer.watch_picker(move |event| {
448 let _ = sender.send(event);
449 });
450 capturer.ensure_picker_visible();
451 }
452 let event = loop {
453 if stop.load(Ordering::SeqCst) {
454 return;
455 }
456 if !delegated {
457 capturer.capture_frame();
458 }
459 match receiver.recv_timeout(Duration::from_millis(40)) {
460 Ok(event) => break event,
461 Err(std::sync::mpsc::RecvTimeoutError::Timeout) => continue,
462 Err(std::sync::mpsc::RecvTimeoutError::Disconnected) => {
463 outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));
464 return;
465 }
466 }
467 };
468 if stop.load(Ordering::SeqCst) {
469 return;
470 }
471 // The portal already bound this stream. Looking the source up again, or
472 // selecting that id, is what used to tear the stream down and report
473 // "the shared source is gone".
474 let source = if event == PortalPickerEvent::Selected {
475 selected.store(true, Ordering::SeqCst);
476 Some(ShareSource {
477 id: 0,
478 kind,
479 title: String::new(),
480 })
481 } else {
482 None
483 };
484 let follow = portal_follow_up(event, source);
485 if !matches!(follow, PortalFollowUp::Share(_)) {
486 outcome(follow);
487 return;
488 }
489 capturer.capture_frame();
490 outcome(follow);
491 while !stop.load(Ordering::SeqCst) {
492 capturer.capture_frame();
493 std::thread::sleep(Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1));
494 }
495 })
496 .map_err(|error| Error::Webrtc(format!("portal thread: {error}")))
497}
498
499#[cfg(test)]
500mod tests {
501 use super::*;
502
503 #[test]
504 fn a_wide_share_fits_the_send_budget_and_a_short_buffer_does_not() {
505 use libwebrtc::video_frame::VideoBuffer;
506 let (width, height) = fit_share_size(2560, 1440, SHARE_SEND_MAX_FS);
507 assert!(macroblocks(width, height) <= SHARE_SEND_MAX_FS);
508 let bytes = vec![0u8; 2560 * 1440 * 4];
509 let frame = share_frame(&bytes, 2560, 1440, 2560 * 4).expect("scaled");
510 assert!(macroblocks(frame.width(), frame.height()) <= SHARE_SEND_MAX_FS);
511 assert!(share_frame(&[0u8; 8], 4, 2, 16).is_none());
512 }
513
514 #[test]
515 fn sources_get_readable_labels() {
516 let screen = ShareSource {
517 id: 1,
518 kind: ShareKind::Screen,
519 title: String::new(),
520 };
521 assert_eq!(screen.label(), "Entire screen");
522 let window = ShareSource {
523 id: 2,
524 kind: ShareKind::Window,
525 title: " Notes ".into(),
526 };
527 assert_eq!(window.label(), "Notes");
528 }
529
530 #[test]
531 fn frames_report_the_macos_picker_outcome() {
532 assert_eq!(
533 picker_event_from_frame(&Ok(())),
534 Some(PortalPickerEvent::Selected)
535 );
536 assert_eq!(
537 picker_event_from_frame::<()>(&Err(CaptureError::Permanent)),
538 Some(PortalPickerEvent::Cancelled)
539 );
540 assert_eq!(
541 picker_event_from_frame::<()>(&Err(CaptureError::Temporary)),
542 None
543 );
544 }
545}
546
547#[cfg(test)]
548mod thumbnail_tests {
549 use super::scaled_bgra;
550
551 #[test]
552 fn a_thumbnail_keeps_the_aspect_and_drops_the_row_padding() {
553 let (width, height, stride) = (8u32, 4u32, 40u32);
554 let mut bytes = vec![0u8; (stride * height) as usize];
555 for row in 0..height as usize {
556 for column in 0..width as usize {
557 let offset = row * stride as usize + column * 4;
558 bytes[offset..offset + 4].copy_from_slice(&[column as u8, row as u8, 7, 0]);
559 }
560 }
561 let picture = scaled_bgra(&bytes, width, height, stride, 4, 4).unwrap();
562 assert_eq!((picture.width, picture.height), (4, 2));
563 assert_eq!(picture.bgra.len(), 4 * 2 * 4);
564 assert_eq!(&picture.bgra[4..8], &[2, 0, 7, 255]);
565 assert!(scaled_bgra(&bytes, width, height, 8, 4, 4).is_none());
566 }
567}
568
569#[cfg(test)]
570mod portal_mode_tests {
571 use super::{
572 ShareKind, SharePicker, ShareSource, share_picker_for_host, share_sources_for_menu,
573 };
574
575 #[test]
576 fn portal_mode_follows_wayland_display_and_skips_the_menu_list() {
577 assert_eq!(share_picker_for_host(false, None), SharePicker::List);
578 assert_eq!(share_picker_for_host(false, Some("")), SharePicker::List);
579 assert_eq!(
580 share_picker_for_host(false, Some("wayland-1")),
581 SharePicker::Portal
582 );
583 assert_eq!(share_picker_for_host(true, None), SharePicker::Portal);
584 assert_eq!(share_picker_for_host(true, Some("")), SharePicker::Portal);
585 let sources = vec![ShareSource {
586 id: 1,
587 kind: ShareKind::Screen,
588 title: "Desk".into(),
589 }];
590 assert!(share_sources_for_menu(SharePicker::Portal, sources.clone()).is_empty());
591 assert_eq!(
592 share_sources_for_menu(SharePicker::List, sources.clone()),
593 sources
594 );
595 }
596}
597
598#[cfg(test)]
599mod portal_share_tests {
600 use libwebrtc::desktop_capturer::PortalPickerEvent;
601
602 use super::{
603 PORTAL_UNAVAILABLE_NOTICE, PortalFollowUp, ShareKind, ShareSource, portal_follow_up,
604 };
605
606 #[test]
607 fn portal_share_cancel_is_quiet_and_failure_is_a_notice() {
608 let source = ShareSource {
609 id: 7,
610 kind: ShareKind::Screen,
611 title: "Desk".into(),
612 };
613 assert!(matches!(
614 portal_follow_up(PortalPickerEvent::Selected, Some(source.clone())),
615 PortalFollowUp::Share(chosen) if chosen == source
616 ));
617 assert!(matches!(
618 portal_follow_up(PortalPickerEvent::Selected, None),
619 PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE)
620 ));
621 assert!(matches!(
622 portal_follow_up(PortalPickerEvent::Cancelled, Some(source.clone())),
623 PortalFollowUp::Quiet
624 ));
625 assert!(matches!(
626 portal_follow_up(PortalPickerEvent::Failed, Some(source)),
627 PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE)
628 ));
629 }
630}
631
632#[cfg(all(test, target_os = "linux"))]
633mod portal_loop_tests {
634 #[test]
635 fn portal_loop_stays_up_across_ensures() {
636 libwebrtc::desktop_capturer::ensure_shared_glib_loop();
637 let id = libwebrtc::desktop_capturer::shared_glib_loop_id();
638 assert_ne!(id, 0);
639 libwebrtc::desktop_capturer::ensure_shared_glib_loop();
640 assert_eq!(id, libwebrtc::desktop_capturer::shared_glib_loop_id());
641 }
642}
643
644#[cfg(all(test, target_os = "linux"))]
645mod portal_smoke {
646 use std::sync::Arc;
647 use std::sync::atomic::{AtomicU32, Ordering};
648 use std::time::Duration;
649
650 use super::{PortalFollowUp, ShareKind, start_portal_capture};
651
652 #[test]
653 fn portal_smoke_captures_after_the_dialog() {
654 if std::env::var("PORTAL_SMOKE").ok().as_deref() != Some("1") {
655 return;
656 }
657 let frames = Arc::new(AtomicU32::new(0));
658 let counter = frames.clone();
659 let (sender, receiver) = std::sync::mpsc::channel();
660 let capture = start_portal_capture(
661 ShareKind::Screen,
662 Arc::new(AtomicU32::new(5)),
663 move |_| {
664 counter.fetch_add(1, Ordering::Relaxed);
665 },
666 move |follow| {
667 eprintln!("PORTAL_FOLLOW={follow:?}");
668 let _ = sender.send(follow);
669 },
670 )
671 .expect("portal thread");
672 let follow = receiver
673 .recv_timeout(Duration::from_secs(40))
674 .expect("no portal result in 40s");
675 std::thread::sleep(Duration::from_millis(700));
676 let count = frames.load(Ordering::Relaxed);
677 eprintln!("PORTAL_FRAMES={count}");
678 drop(capture);
679 match follow {
680 PortalFollowUp::Share(_) => {
681 assert!(count > 0, "the dialog confirmed, but no frame arrived")
682 }
683 PortalFollowUp::Quiet => panic!("the dialog was cancelled"),
684 PortalFollowUp::Notice(text) => panic!("portal notice: {text}"),
685 }
686 }
687}