Allow joining remote projects in zed2

Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-12-04 17:06:08 -08:00
parent 959b2961ff
commit 71a1125e88

View file

@ -4245,95 +4245,82 @@ pub fn join_remote_project(
app_state: Arc<AppState>, app_state: Arc<AppState>,
cx: &mut AppContext, cx: &mut AppContext,
) -> Task<Result<()>> { ) -> Task<Result<()>> {
todo!() let windows = cx.windows();
// let windows = cx.windows(); cx.spawn(|mut cx| async move {
// cx.spawn(|mut cx| async move { let existing_workspace = windows.into_iter().find_map(|window| {
// let existing_workspace = windows.into_iter().find_map(|window| { window.downcast::<Workspace>().and_then(|window| {
// window.downcast::<Workspace>().and_then(|window| { window
// window .update(&mut cx, |workspace, cx| {
// .update(&mut cx, |workspace, cx| { if workspace.project().read(cx).remote_id() == Some(project_id) {
// if workspace.project().read(cx).remote_id() == Some(project_id) { Some(window)
// Some(cx.view().downgrade()) } else {
// } else { None
// None }
// } })
// }) .unwrap_or(None)
// .unwrap_or(None) })
// }) });
// });
// let workspace = if let Some(existing_workspace) = existing_workspace { let workspace = if let Some(existing_workspace) = existing_workspace {
// existing_workspace existing_workspace
// } else { } else {
// let active_call = cx.update(ActiveCall::global); let active_call = cx.update(|cx| ActiveCall::global(cx))?;
// let room = active_call let room = active_call
// .read_with(&cx, |call, _| call.room().cloned()) .read_with(&cx, |call, _| call.room().cloned())?
// .ok_or_else(|| anyhow!("not in a call"))?; .ok_or_else(|| anyhow!("not in a call"))?;
// let project = room let project = room
// .update(&mut cx, |room, cx| { .update(&mut cx, |room, cx| {
// room.join_project( room.join_project(
// project_id, project_id,
// app_state.languages.clone(), app_state.languages.clone(),
// app_state.fs.clone(), app_state.fs.clone(),
// cx, cx,
// ) )
// }) })?
// .await?; .await?;
// let window_bounds_override = window_bounds_env_override(&cx); let window_bounds_override = window_bounds_env_override(&cx);
// let window = cx.add_window( cx.update(|cx| {
// (app_state.build_window_options)( let options = (app_state.build_window_options)(window_bounds_override, None, cx);
// window_bounds_override, cx.open_window(options, |cx| {
// None, cx.build_view(|cx| Workspace::new(0, project, app_state.clone(), cx))
// cx.platform().as_ref(), })
// ), })?
// |cx| Workspace::new(0, project, app_state.clone(), cx), };
// );
// let workspace = window.root(&cx).unwrap();
// (app_state.initialize_workspace)(
// workspace.downgrade(),
// false,
// app_state.clone(),
// cx.clone(),
// )
// .await
// .log_err();
// workspace.downgrade() workspace.update(&mut cx, |workspace, cx| {
// }; cx.activate(true);
cx.activate_window();
// workspace.window().activate(&mut cx); if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
// cx.platform().activate(true); let follow_peer_id = room
.read(cx)
// workspace.update(&mut cx, |workspace, cx| { .remote_participants()
// if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() { .iter()
// let follow_peer_id = room .find(|(_, participant)| participant.user.id == follow_user_id)
// .read(cx) .map(|(_, p)| p.peer_id)
// .remote_participants() .or_else(|| {
// .iter() // If we couldn't follow the given user, follow the host instead.
// .find(|(_, participant)| participant.user.id == follow_user_id) let collaborator = workspace
// .map(|(_, p)| p.peer_id) .project()
// .or_else(|| { .read(cx)
// // If we couldn't follow the given user, follow the host instead. .collaborators()
// let collaborator = workspace .values()
// .project() .find(|collaborator| collaborator.replica_id == 0)?;
// .read(cx) Some(collaborator.peer_id)
// .collaborators() });
// .values()
// .find(|collaborator| collaborator.replica_id == 0)?;
// Some(collaborator.peer_id)
// });
// todo!("uncomment following")
// if let Some(follow_peer_id) = follow_peer_id { // if let Some(follow_peer_id) = follow_peer_id {
// workspace // workspace
// .follow(follow_peer_id, cx) // .follow(follow_peer_id, cx)
// .map(|follow| follow.detach_and_log_err(cx)); // .map(|follow| follow.detach_and_log_err(cx));
// } // }
// } }
// })?; })?;
// anyhow::Ok(()) anyhow::Ok(())
// }) })
} }
pub fn restart(_: &Restart, cx: &mut AppContext) { pub fn restart(_: &Restart, cx: &mut AppContext) {