title_bar: Fix screensharing errors not being shown to the user (#36424)
Release Notes: - N/A
This commit is contained in:
parent
e1d8e3bf6d
commit
ed155ceba9
1 changed files with 50 additions and 45 deletions
|
@ -14,7 +14,6 @@ use ui::{
|
||||||
Avatar, AvatarAudioStatusIndicator, ContextMenu, ContextMenuItem, Divider, DividerColor,
|
Avatar, AvatarAudioStatusIndicator, ContextMenu, ContextMenuItem, Divider, DividerColor,
|
||||||
Facepile, PopoverMenu, SplitButton, SplitButtonStyle, TintColor, Tooltip, prelude::*,
|
Facepile, PopoverMenu, SplitButton, SplitButtonStyle, TintColor, Tooltip, prelude::*,
|
||||||
};
|
};
|
||||||
use util::maybe;
|
|
||||||
use workspace::notifications::DetachAndPromptErr;
|
use workspace::notifications::DetachAndPromptErr;
|
||||||
|
|
||||||
use crate::TitleBar;
|
use crate::TitleBar;
|
||||||
|
@ -32,12 +31,16 @@ actions!(
|
||||||
);
|
);
|
||||||
|
|
||||||
fn toggle_screen_sharing(
|
fn toggle_screen_sharing(
|
||||||
screen: Option<Rc<dyn ScreenCaptureSource>>,
|
screen: anyhow::Result<Option<Rc<dyn ScreenCaptureSource>>>,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) {
|
) {
|
||||||
let call = ActiveCall::global(cx).read(cx);
|
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 toggle_screen_sharing = room.update(cx, |room, cx| {
|
||||||
let clicked_on_currently_shared_screen =
|
let clicked_on_currently_shared_screen =
|
||||||
room.shared_screen_id().is_some_and(|screen_id| {
|
room.shared_screen_id().is_some_and(|screen_id| {
|
||||||
|
@ -76,8 +79,11 @@ fn toggle_screen_sharing(
|
||||||
Task::ready(Ok(()))
|
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) {
|
fn toggle_mute(_: &ToggleMute, cx: &mut App) {
|
||||||
|
@ -483,9 +489,8 @@ impl TitleBar {
|
||||||
let screen = if should_share {
|
let screen = if should_share {
|
||||||
cx.update(|_, cx| pick_default_screen(cx))?.await
|
cx.update(|_, cx| pick_default_screen(cx))?.await
|
||||||
} else {
|
} else {
|
||||||
None
|
Ok(None)
|
||||||
};
|
};
|
||||||
|
|
||||||
cx.update(|window, cx| toggle_screen_sharing(screen, window, cx))?;
|
cx.update(|window, cx| toggle_screen_sharing(screen, window, cx))?;
|
||||||
|
|
||||||
Result::<_, anyhow::Error>::Ok(())
|
Result::<_, anyhow::Error>::Ok(())
|
||||||
|
@ -571,7 +576,7 @@ impl TitleBar {
|
||||||
selectable: true,
|
selectable: true,
|
||||||
documentation_aside: None,
|
documentation_aside: None,
|
||||||
handler: Rc::new(move |_, window, cx| {
|
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.
|
/// 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();
|
let source = cx.screen_capture_sources();
|
||||||
cx.spawn(async move |_| {
|
cx.spawn(async move |_| {
|
||||||
let available_sources = maybe!(async move { source.await? }).await.ok()?;
|
let available_sources = source.await??;
|
||||||
available_sources
|
Ok(available_sources
|
||||||
.iter()
|
.iter()
|
||||||
.find(|it| {
|
.find(|it| {
|
||||||
it.as_ref()
|
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())
|
.is_ok_and(|meta| meta.is_main.unwrap_or_default())
|
||||||
})
|
})
|
||||||
.or_else(|| available_sources.iter().next())
|
.or_else(|| available_sources.iter().next())
|
||||||
.cloned()
|
.cloned())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue