Fix prevention of cross-channel joins

Co-Authored-By: Max <max@zed.dev>
This commit is contained in:
Conrad Irwin 2024-01-08 11:14:25 -07:00
parent 3541dd8a6d
commit ed76315387
4 changed files with 54 additions and 42 deletions

View file

@ -26,12 +26,12 @@ use futures::{
};
use gpui::{
actions, canvas, div, impl_actions, point, size, Action, AnyElement, AnyModel, AnyView,
AnyWeakView, AnyWindowHandle, AppContext, AsyncAppContext, AsyncWindowContext, BorrowWindow,
Bounds, Context, Div, DragMoveEvent, Element, Entity, EntityId, EventEmitter, FocusHandle,
FocusableView, GlobalPixels, InteractiveElement, IntoElement, KeyContext, LayoutId,
ManagedView, Model, ModelContext, ParentElement, PathPromptOptions, Pixels, Point, PromptLevel,
Render, Size, Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView,
WindowBounds, WindowContext, WindowHandle, WindowOptions,
AnyWeakView, AppContext, AsyncAppContext, AsyncWindowContext, BorrowWindow, Bounds, Context,
Div, DragMoveEvent, Element, Entity, EntityId, EventEmitter, FocusHandle, FocusableView,
GlobalPixels, InteractiveElement, IntoElement, KeyContext, LayoutId, ManagedView, Model,
ModelContext, ParentElement, PathPromptOptions, Pixels, Point, PromptLevel, Render, Size,
Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView, WindowBounds,
WindowContext, WindowHandle, WindowOptions,
};
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};
use itertools::Itertools;
@ -4034,34 +4034,34 @@ pub fn join_channel(
return anyhow::Ok(());
}
if requesting_window.is_some() {
return anyhow::Ok(());
}
// find an existing workspace to focus and show call controls
let mut active_window = activate_any_workspace_window(&mut cx);
let mut active_window =
requesting_window.or_else(|| activate_any_workspace_window(&mut cx));
if active_window.is_none() {
// no open workspaces, make one to show the error in (blergh)
cx.update(|cx| Workspace::new_local(vec![], app_state.clone(), requesting_window, cx))?
let (window_handle, _) = cx
.update(|cx| {
Workspace::new_local(vec![], app_state.clone(), requesting_window, cx)
})?
.await?;
active_window = Some(window_handle);
}
active_window = activate_any_workspace_window(&mut cx);
let Some(active_window) = active_window else {
return anyhow::Ok(());
};
if let Err(err) = result {
active_window
.update(&mut cx, |_, cx| {
cx.prompt(
PromptLevel::Critical,
&format!("Failed to join channel: {}", err),
&["Ok"],
)
})?
.await
.ok();
log::error!("failed to join channel: {}", err);
if let Some(active_window) = active_window {
active_window
.update(&mut cx, |_, cx| {
cx.prompt(
PromptLevel::Critical,
&format!("Failed to join channel: {}", err),
&["Ok"],
)
})?
.await
.ok();
}
}
// return ok, we showed the error to the user.
@ -4079,19 +4079,17 @@ pub async fn get_any_active_workspace(
cx.update(|cx| Workspace::new_local(vec![], app_state.clone(), None, cx))?
.await?;
}
activate_any_workspace_window(&mut cx)
.context("could not open zed")?
.downcast::<Workspace>()
.context("could not open zed workspace window")
activate_any_workspace_window(&mut cx).context("could not open zed")
}
fn activate_any_workspace_window(cx: &mut AsyncAppContext) -> Option<AnyWindowHandle> {
fn activate_any_workspace_window(cx: &mut AsyncAppContext) -> Option<WindowHandle<Workspace>> {
cx.update(|cx| {
for window in cx.windows() {
let is_workspace = window.downcast::<Workspace>().is_some();
if is_workspace {
window.update(cx, |_, cx| cx.activate_window()).ok();
return Some(window);
if let Some(workspace_window) = window.downcast::<Workspace>() {
workspace_window
.update(cx, |_, cx| cx.activate_window())
.ok();
return Some(workspace_window);
}
}
None