cfg-out call-related workspace functionality

This commit is contained in:
Kirill Bulatov 2025-08-25 15:58:41 +03:00
parent cc680d280d
commit 775160a199
3 changed files with 209 additions and 64 deletions

View file

@ -394,6 +394,16 @@ impl ActiveCall {
} }
} }
#[cfg(not(feature = "call"))]
pub fn unshare_project(
&mut self,
_project: Entity<Project>,
_cx: &mut Context<Self>,
) -> Result<()> {
Ok(())
}
#[cfg(feature = "call")]
pub fn unshare_project( pub fn unshare_project(
&mut self, &mut self,
project: Entity<Project>, project: Entity<Project>,

View file

@ -4,11 +4,14 @@ use crate::{
workspace_settings::{PaneSplitDirectionHorizontal, PaneSplitDirectionVertical}, workspace_settings::{PaneSplitDirectionHorizontal, PaneSplitDirectionVertical},
}; };
use anyhow::Result; use anyhow::Result;
#[cfg(feature = "call")]
use call::{ActiveCall, ParticipantLocation}; use call::{ActiveCall, ParticipantLocation};
use collections::HashMap; use collections::HashMap;
use gpui::{ use gpui::{
Along, AnyView, AnyWeakView, Axis, Bounds, Entity, Hsla, IntoElement, MouseButton, Pixels, Along, AnyView, AnyWeakView, Axis, Bounds, Entity, Hsla, IntoElement, Pixels, Point,
Point, StyleRefinement, WeakEntity, Window, point, size, StyleRefinement, WeakEntity, Window, point, size,
}; };
use parking_lot::Mutex; use parking_lot::Mutex;
use project::Project; use project::Project;
@ -197,6 +200,7 @@ pub enum Member {
pub struct PaneRenderContext<'a> { pub struct PaneRenderContext<'a> {
pub project: &'a Entity<Project>, pub project: &'a Entity<Project>,
pub follower_states: &'a HashMap<CollaboratorId, FollowerState>, pub follower_states: &'a HashMap<CollaboratorId, FollowerState>,
#[cfg(feature = "call")]
pub active_call: Option<&'a Entity<ActiveCall>>, pub active_call: Option<&'a Entity<ActiveCall>>,
pub active_pane: &'a Entity<Pane>, pub active_pane: &'a Entity<Pane>,
pub app_state: &'a Arc<AppState>, pub app_state: &'a Arc<AppState>,
@ -258,6 +262,11 @@ impl PaneLeaderDecorator for PaneRenderContext<'_> {
let mut leader_color; let mut leader_color;
let status_box; let status_box;
match leader_id { match leader_id {
#[cfg(not(feature = "call"))]
CollaboratorId::PeerId(_) => {
return LeaderDecoration::default();
}
#[cfg(feature = "call")]
CollaboratorId::PeerId(peer_id) => { CollaboratorId::PeerId(peer_id) => {
let Some(leader) = self.active_call.as_ref().and_then(|call| { let Some(leader) = self.active_call.as_ref().and_then(|call| {
let room = call.read(cx).room()?.read(cx); let room = call.read(cx).room()?.read(cx);
@ -315,7 +324,7 @@ impl PaneLeaderDecorator for PaneRenderContext<'_> {
|this, (leader_project_id, leader_user_id)| { |this, (leader_project_id, leader_user_id)| {
let app_state = self.app_state.clone(); let app_state = self.app_state.clone();
this.cursor_pointer().on_mouse_down( this.cursor_pointer().on_mouse_down(
MouseButton::Left, gpui::MouseButton::Left,
move |_, _, cx| { move |_, _, cx| {
crate::join_in_room_project( crate::join_in_room_project(
leader_project_id, leader_project_id,

View file

@ -9,6 +9,7 @@ pub mod pane_group;
mod path_list; mod path_list;
mod persistence; mod persistence;
pub mod searchable; pub mod searchable;
#[cfg(feature = "call")]
pub mod shared_screen; pub mod shared_screen;
mod status_bar; mod status_bar;
pub mod tasks; pub mod tasks;
@ -22,11 +23,17 @@ pub use dock::Panel;
pub use path_list::PathList; pub use path_list::PathList;
pub use toast_layer::{ToastAction, ToastLayer, ToastView}; pub use toast_layer::{ToastAction, ToastLayer, ToastView};
use anyhow::{Context as _, Result, anyhow}; #[cfg(feature = "call")]
use call::{ActiveCall, call_settings::CallSettings}; use call::{ActiveCall, call_settings::CallSettings};
#[cfg(feature = "call")]
use client::{Status, proto::ErrorCode};
#[cfg(feature = "call")]
use shared_screen::SharedScreen;
use anyhow::{Context as _, Result, anyhow};
use client::{ use client::{
ChannelId, Client, ErrorExt, Status, TypedEnvelope, UserStore, ChannelId, Client, ErrorExt, TypedEnvelope, UserStore,
proto::{self, ErrorCode, PanelId, PeerId}, proto::{self, PanelId, PeerId},
}; };
use collections::{HashMap, HashSet, hash_map}; use collections::{HashMap, HashSet, hash_map};
use dock::{Dock, DockPosition, PanelButtons, PanelHandle, RESIZE_HANDLE_SIZE}; use dock::{Dock, DockPosition, PanelButtons, PanelHandle, RESIZE_HANDLE_SIZE};
@ -79,7 +86,6 @@ use schemars::JsonSchema;
use serde::Deserialize; use serde::Deserialize;
use session::AppSession; use session::AppSession;
use settings::{Settings, update_settings_file}; use settings::{Settings, update_settings_file};
use shared_screen::SharedScreen;
use sqlez::{ use sqlez::{
bindable::{Bind, Column, StaticColumnCount}, bindable::{Bind, Column, StaticColumnCount},
statement::Statement, statement::Statement,
@ -886,6 +892,7 @@ impl Global for GlobalAppState {}
pub struct WorkspaceStore { pub struct WorkspaceStore {
workspaces: HashSet<WindowHandle<Workspace>>, workspaces: HashSet<WindowHandle<Workspace>>,
#[cfg(feature = "call")]
client: Arc<Client>, client: Arc<Client>,
_subscriptions: Vec<client::Subscription>, _subscriptions: Vec<client::Subscription>,
} }
@ -1117,6 +1124,7 @@ pub struct Workspace {
window_edited: bool, window_edited: bool,
last_window_title: Option<String>, last_window_title: Option<String>,
dirty_items: HashMap<EntityId, Subscription>, dirty_items: HashMap<EntityId, Subscription>,
#[cfg(feature = "call")]
active_call: Option<(Entity<ActiveCall>, Vec<Subscription>)>, active_call: Option<(Entity<ActiveCall>, Vec<Subscription>)>,
leader_updates_tx: mpsc::UnboundedSender<(PeerId, proto::UpdateFollowers)>, leader_updates_tx: mpsc::UnboundedSender<(PeerId, proto::UpdateFollowers)>,
database_id: Option<WorkspaceId>, database_id: Option<WorkspaceId>,
@ -1158,6 +1166,7 @@ pub struct FollowerState {
struct FollowerView { struct FollowerView {
view: Box<dyn FollowableItemHandle>, view: Box<dyn FollowableItemHandle>,
#[cfg(feature = "call")]
location: Option<proto::PanelId>, location: Option<proto::PanelId>,
} }
@ -1357,10 +1366,15 @@ impl Workspace {
let session_id = app_state.session.read(cx).id().to_owned(); let session_id = app_state.session.read(cx).id().to_owned();
#[cfg(feature = "call")]
let mut active_call = None; let mut active_call = None;
if let Some(call) = ActiveCall::try_global(cx) { #[cfg(feature = "call")]
let subscriptions = vec![cx.subscribe_in(&call, window, Self::on_active_call_event)]; {
active_call = Some((call, subscriptions)); if let Some(call) = ActiveCall::try_global(cx) {
let subscriptions =
vec![cx.subscribe_in(&call, window, Self::on_active_call_event)];
active_call = Some((call, subscriptions));
}
} }
let (serializable_items_tx, serializable_items_rx) = let (serializable_items_tx, serializable_items_rx) =
@ -1446,6 +1460,7 @@ impl Workspace {
window_edited: false, window_edited: false,
last_window_title: None, last_window_title: None,
dirty_items: Default::default(), dirty_items: Default::default(),
#[cfg(feature = "call")]
active_call, active_call,
database_id: workspace_id, database_id: workspace_id,
app_state, app_state,
@ -2250,6 +2265,7 @@ impl Workspace {
window: &mut Window, window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> Task<Result<bool>> { ) -> Task<Result<bool>> {
#[cfg(feature = "call")]
let active_call = self.active_call().cloned(); let active_call = self.active_call().cloned();
// On Linux and Windows, closing the last window should restore the last workspace. // On Linux and Windows, closing the last window should restore the last workspace.
@ -2258,51 +2274,58 @@ impl Workspace {
&& cx.windows().len() == 1; && cx.windows().len() == 1;
cx.spawn_in(window, async move |this, cx| { cx.spawn_in(window, async move |this, cx| {
let workspace_count = cx.update(|_window, cx| { #[cfg(feature = "call")]
cx.windows()
.iter()
.filter(|window| window.downcast::<Workspace>().is_some())
.count()
})?;
if let Some(active_call) = active_call
&& workspace_count == 1
&& active_call.read_with(cx, |call, _| call.room().is_some())?
{ {
if close_intent == CloseIntent::CloseWindow { let workspace_count = cx.update(|_window, cx| {
let answer = cx.update(|window, cx| { cx.windows()
window.prompt( .iter()
PromptLevel::Warning, .filter(|window| window.downcast::<Workspace>().is_some())
"Do you want to leave the current call?", .count()
None, })?;
&["Close window and hang up", "Cancel"], if let Some(active_call) = active_call
cx, && workspace_count == 1
) && active_call.read_with(cx, |call, _| call.room().is_some())?
})?; {
if close_intent == CloseIntent::CloseWindow {
let answer = cx.update(|window, cx| {
window.prompt(
PromptLevel::Warning,
"Do you want to leave the current call?",
None,
&["Close window and hang up", "Cancel"],
cx,
)
})?;
if answer.await.log_err() == Some(1) { if answer.await.log_err() == Some(1) {
return anyhow::Ok(false); return anyhow::Ok(false);
} else { } else {
active_call {
.update(cx, |call, cx| call.hang_up(cx))? active_call
.await .update(cx, |call, cx| call.hang_up(cx))?
.log_err(); .await
} .log_err();
} }
if close_intent == CloseIntent::ReplaceWindow {
_ = active_call.update(cx, |this, cx| {
let workspace = cx
.windows()
.iter()
.filter_map(|window| window.downcast::<Workspace>())
.next()
.unwrap();
let project = workspace.read(cx)?.project.clone();
if project.read(cx).is_shared() {
this.unshare_project(project, cx)?;
} }
Ok::<_, anyhow::Error>(()) }
})?; if close_intent == CloseIntent::ReplaceWindow {
#[cfg(feature = "call")]
{
_ = active_call.update(cx, |active_call, cx| {
let workspace = cx
.windows()
.iter()
.filter_map(|window| window.downcast::<Workspace>())
.next()
.unwrap();
let project = workspace.read(cx)?.project.clone();
if project.read(cx).is_shared() {
active_call.unshare_project(project, cx)?;
}
Ok::<_, anyhow::Error>(())
})?;
}
}
} }
} }
@ -3486,6 +3509,7 @@ impl Workspace {
item item
} }
#[cfg(feature = "call")]
pub fn open_shared_screen( pub fn open_shared_screen(
&mut self, &mut self,
peer_id: PeerId, peer_id: PeerId,
@ -3907,8 +3931,11 @@ impl Workspace {
pane.update(cx, |pane, _| { pane.update(cx, |pane, _| {
pane.track_alternate_file_items(); pane.track_alternate_file_items();
}); });
if *local { #[cfg(feature = "call")]
self.unfollow_in_pane(pane, window, cx); {
if *local {
self.unfollow_in_pane(pane, window, cx);
}
} }
serialize_workspace = *focus_changed || pane != self.active_pane(); serialize_workspace = *focus_changed || pane != self.active_pane();
if pane == self.active_pane() { if pane == self.active_pane() {
@ -3973,6 +4000,17 @@ impl Workspace {
} }
} }
#[cfg(not(feature = "call"))]
pub fn unfollow_in_pane(
&mut self,
_pane: &Entity<Pane>,
_window: &mut Window,
_cx: &mut Context<Workspace>,
) -> Option<CollaboratorId> {
None
}
#[cfg(feature = "call")]
pub fn unfollow_in_pane( pub fn unfollow_in_pane(
&mut self, &mut self,
pane: &Entity<Pane>, pane: &Entity<Pane>,
@ -4122,6 +4160,7 @@ impl Workspace {
cx.notify(); cx.notify();
} }
#[cfg(feature = "call")]
pub fn start_following( pub fn start_following(
&mut self, &mut self,
leader_id: impl Into<CollaboratorId>, leader_id: impl Into<CollaboratorId>,
@ -4185,6 +4224,16 @@ impl Workspace {
} }
} }
#[cfg(not(feature = "call"))]
pub fn follow_next_collaborator(
&mut self,
_: &FollowNextCollaborator,
_window: &mut Window,
_cx: &mut Context<Self>,
) {
}
#[cfg(feature = "call")]
pub fn follow_next_collaborator( pub fn follow_next_collaborator(
&mut self, &mut self,
_: &FollowNextCollaborator, _: &FollowNextCollaborator,
@ -4233,6 +4282,16 @@ impl Workspace {
} }
} }
#[cfg(not(feature = "call"))]
pub fn follow(
&mut self,
_leader_id: impl Into<CollaboratorId>,
_window: &mut Window,
_cx: &mut Context<Self>,
) {
}
#[cfg(feature = "call")]
pub fn follow( pub fn follow(
&mut self, &mut self,
leader_id: impl Into<CollaboratorId>, leader_id: impl Into<CollaboratorId>,
@ -4285,6 +4344,17 @@ impl Workspace {
} }
} }
#[cfg(not(feature = "call"))]
pub fn unfollow(
&mut self,
_leader_id: impl Into<CollaboratorId>,
_window: &mut Window,
_cx: &mut Context<Self>,
) -> Option<()> {
None
}
#[cfg(feature = "call")]
pub fn unfollow( pub fn unfollow(
&mut self, &mut self,
leader_id: impl Into<CollaboratorId>, leader_id: impl Into<CollaboratorId>,
@ -4595,6 +4665,7 @@ impl Workspace {
anyhow::bail!("no id for view"); anyhow::bail!("no id for view");
}; };
let id = ViewId::from_proto(id)?; let id = ViewId::from_proto(id)?;
#[cfg(feature = "call")]
let panel_id = view.panel_id.and_then(proto::PanelId::from_i32); let panel_id = view.panel_id.and_then(proto::PanelId::from_i32);
let pane = this.update(cx, |this, _cx| { let pane = this.update(cx, |this, _cx| {
@ -4667,6 +4738,7 @@ impl Workspace {
id, id,
FollowerView { FollowerView {
view: item, view: item,
#[cfg(feature = "call")]
location: panel_id, location: panel_id,
}, },
); );
@ -4721,6 +4793,7 @@ impl Workspace {
view.map(|view| { view.map(|view| {
entry.insert(FollowerView { entry.insert(FollowerView {
view, view,
#[cfg(feature = "call")]
location: None, location: None,
}) })
}) })
@ -4911,6 +4984,17 @@ impl Workspace {
) )
} }
#[cfg(not(feature = "call"))]
fn active_item_for_peer(
&self,
_peer_id: PeerId,
_window: &mut Window,
_cx: &mut Context<Self>,
) -> Option<(Option<PanelId>, Box<dyn ItemHandle>)> {
None
}
#[cfg(feature = "call")]
fn active_item_for_peer( fn active_item_for_peer(
&self, &self,
peer_id: PeerId, peer_id: PeerId,
@ -4952,6 +5036,7 @@ impl Workspace {
item_to_activate item_to_activate
} }
#[cfg(feature = "call")]
fn shared_screen_for_peer( fn shared_screen_for_peer(
&self, &self,
peer_id: PeerId, peer_id: PeerId,
@ -5002,6 +5087,7 @@ impl Workspace {
} }
} }
#[cfg(feature = "call")]
pub fn active_call(&self) -> Option<&Entity<ActiveCall>> { pub fn active_call(&self) -> Option<&Entity<ActiveCall>> {
self.active_call.as_ref().map(|(call, _)| call) self.active_call.as_ref().map(|(call, _)| call)
} }
@ -5023,16 +5109,6 @@ impl Workspace {
} }
} }
#[cfg(not(feature = "call"))]
fn on_active_call_event(
&mut self,
_: &Entity<ActiveCall>,
_: &call::room::Event,
_: &mut Window,
_: &mut Context<Self>,
) {
}
pub fn database_id(&self) -> Option<WorkspaceId> { pub fn database_id(&self) -> Option<WorkspaceId> {
self.database_id self.database_id
} }
@ -5929,6 +6005,17 @@ impl Workspace {
} }
} }
#[cfg(not(feature = "call"))]
fn leader_border_for_pane(
_follower_states: &HashMap<CollaboratorId, FollowerState>,
_pane: &Entity<Pane>,
_: &Window,
_cx: &App,
) -> Option<Div> {
None
}
#[cfg(feature = "call")]
fn leader_border_for_pane( fn leader_border_for_pane(
follower_states: &HashMap<CollaboratorId, FollowerState>, follower_states: &HashMap<CollaboratorId, FollowerState>,
pane: &Entity<Pane>, pane: &Entity<Pane>,
@ -6395,6 +6482,7 @@ impl Render for Workspace {
&PaneRenderContext { &PaneRenderContext {
follower_states: follower_states:
&self.follower_states, &self.follower_states,
#[cfg(feature = "call")]
active_call: self.active_call(), active_call: self.active_call(),
active_pane: &self.active_pane, active_pane: &self.active_pane,
app_state: &self.app_state, app_state: &self.app_state,
@ -6459,6 +6547,7 @@ impl Render for Workspace {
&PaneRenderContext { &PaneRenderContext {
follower_states: follower_states:
&self.follower_states, &self.follower_states,
#[cfg(feature = "call")]
active_call: self.active_call(), active_call: self.active_call(),
active_pane: &self.active_pane, active_pane: &self.active_pane,
app_state: &self.app_state, app_state: &self.app_state,
@ -6521,6 +6610,7 @@ impl Render for Workspace {
&PaneRenderContext { &PaneRenderContext {
follower_states: follower_states:
&self.follower_states, &self.follower_states,
#[cfg(feature = "call")]
active_call: self.active_call(), active_call: self.active_call(),
active_pane: &self.active_pane, active_pane: &self.active_pane,
app_state: &self.app_state, app_state: &self.app_state,
@ -6569,6 +6659,7 @@ impl Render for Workspace {
&PaneRenderContext { &PaneRenderContext {
follower_states: follower_states:
&self.follower_states, &self.follower_states,
#[cfg(feature = "call")]
active_call: self.active_call(), active_call: self.active_call(),
active_pane: &self.active_pane, active_pane: &self.active_pane,
app_state: &self.app_state, app_state: &self.app_state,
@ -6642,10 +6733,22 @@ impl WorkspaceStore {
client.add_request_handler(cx.weak_entity(), Self::handle_follow), client.add_request_handler(cx.weak_entity(), Self::handle_follow),
client.add_message_handler(cx.weak_entity(), Self::handle_update_followers), client.add_message_handler(cx.weak_entity(), Self::handle_update_followers),
], ],
#[cfg(feature = "call")]
client, client,
} }
} }
#[cfg(not(feature = "call"))]
pub fn update_followers(
&self,
_project_id: Option<u64>,
_update: proto::update_followers::Variant,
_cx: &App,
) -> Option<()> {
None
}
#[cfg(feature = "call")]
pub fn update_followers( pub fn update_followers(
&self, &self,
project_id: Option<u64>, project_id: Option<u64>,
@ -6811,6 +6914,7 @@ actions!(
] ]
); );
#[cfg(feature = "call")]
async fn join_channel_internal( async fn join_channel_internal(
channel_id: ChannelId, channel_id: ChannelId,
app_state: &Arc<AppState>, app_state: &Arc<AppState>,
@ -6958,6 +7062,17 @@ async fn join_channel_internal(
anyhow::Ok(false) anyhow::Ok(false)
} }
#[cfg(not(feature = "call"))]
pub fn join_channel(
_channel_id: ChannelId,
_app_state: Arc<AppState>,
_requesting_window: Option<WindowHandle<Workspace>>,
_cx: &mut App,
) -> Task<Result<()>> {
Task::ready(Ok(()))
}
#[cfg(feature = "call")]
pub fn join_channel( pub fn join_channel(
channel_id: ChannelId, channel_id: ChannelId,
app_state: Arc<AppState>, app_state: Arc<AppState>,
@ -7465,6 +7580,17 @@ fn serialize_ssh_project(
}) })
} }
#[cfg(not(feature = "call"))]
pub fn join_in_room_project(
_project_id: u64,
_follow_user_id: u64,
_app_state: Arc<AppState>,
_cx: &mut App,
) -> Task<Result<()>> {
Task::ready(Ok(()))
}
#[cfg(feature = "call")]
pub fn join_in_room_project( pub fn join_in_room_project(
project_id: u64, project_id: u64,
follow_user_id: u64, follow_user_id: u64,