title_bar: Fix screensharing errors not being shown to the user (#36424)

Release Notes:

- N/A
This commit is contained in:
Lukas Wirth 2025-08-18 18:27:26 +02:00 committed by GitHub
parent e1d8e3bf6d
commit ed155ceba9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,7 +14,6 @@ use ui::{
Avatar, AvatarAudioStatusIndicator, ContextMenu, ContextMenuItem, Divider, DividerColor,
Facepile, PopoverMenu, SplitButton, SplitButtonStyle, TintColor, Tooltip, prelude::*,
};
use util::maybe;
use workspace::notifications::DetachAndPromptErr;
use crate::TitleBar;
@ -32,12 +31,16 @@ actions!(
);
fn toggle_screen_sharing(
screen: Option<Rc<dyn ScreenCaptureSource>>,
screen: anyhow::Result<Option<Rc<dyn ScreenCaptureSource>>>,
window: &mut Window,
cx: &mut App,
) {
let call = ActiveCall::global(cx).read(cx);
if let Some(room) = call.room().cloned() {
let toggle_screen_sharing = match screen {
Ok(screen) => {
let Some(room) = call.room().cloned() else {
return;
};
let toggle_screen_sharing = room.update(cx, |room, cx| {
let clicked_on_currently_shared_screen =
room.shared_screen_id().is_some_and(|screen_id| {
@ -76,8 +79,11 @@ fn toggle_screen_sharing(
Task::ready(Ok(()))
}
});
toggle_screen_sharing.detach_and_prompt_err("Sharing Screen Failed", window, cx, |e, _, _| Some(format!("{:?}\n\nPlease check that you have given Zed permissions to record your screen in Settings.", e)));
toggle_screen_sharing
}
Err(e) => Task::ready(Err(e)),
};
toggle_screen_sharing.detach_and_prompt_err("Sharing Screen Failed", window, cx, |e, _, _| Some(format!("{:?}\n\nPlease check that you have given Zed permissions to record your screen in Settings.", e)));
}
fn toggle_mute(_: &ToggleMute, cx: &mut App) {
@ -483,9 +489,8 @@ impl TitleBar {
let screen = if should_share {
cx.update(|_, cx| pick_default_screen(cx))?.await
} else {
None
Ok(None)
};
cx.update(|window, cx| toggle_screen_sharing(screen, window, cx))?;
Result::<_, anyhow::Error>::Ok(())
@ -571,7 +576,7 @@ impl TitleBar {
selectable: true,
documentation_aside: None,
handler: Rc::new(move |_, window, cx| {
toggle_screen_sharing(Some(screen.clone()), window, cx);
toggle_screen_sharing(Ok(Some(screen.clone())), window, cx);
}),
});
}
@ -585,11 +590,11 @@ impl TitleBar {
}
/// Picks the screen to share when clicking on the main screen sharing button.
fn pick_default_screen(cx: &App) -> Task<Option<Rc<dyn ScreenCaptureSource>>> {
fn pick_default_screen(cx: &App) -> Task<anyhow::Result<Option<Rc<dyn ScreenCaptureSource>>>> {
let source = cx.screen_capture_sources();
cx.spawn(async move |_| {
let available_sources = maybe!(async move { source.await? }).await.ok()?;
available_sources
let available_sources = source.await??;
Ok(available_sources
.iter()
.find(|it| {
it.as_ref()
@ -597,6 +602,6 @@ fn pick_default_screen(cx: &App) -> Task<Option<Rc<dyn ScreenCaptureSource>>> {
.is_ok_and(|meta| meta.is_main.unwrap_or_default())
})
.or_else(|| available_sources.iter().next())
.cloned()
.cloned())
})
}