ssh remoting: Restore SSH projects when reopening Zed (#19188)

Release Notes:

- N/A

---------

Co-authored-by: Bennet <bennet@zed.dev>
This commit is contained in:
Thorsten Ball 2024-10-14 14:56:25 +02:00 committed by GitHub
parent 71a878aa39
commit 6ec00cdb06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 248 additions and 70 deletions

View file

@ -26,6 +26,7 @@ use gpui::{
use http_client::{read_proxy_from_env, Uri};
use language::LanguageRegistry;
use log::LevelFilter;
use remote::SshConnectionOptions;
use reqwest_client::ReqwestClient;
use assets::Assets;
@ -55,7 +56,7 @@ use uuid::Uuid;
use welcome::{show_welcome_view, BaseKeymap, FIRST_OPEN};
use workspace::{
notifications::{simple_message_notification::MessageNotification, NotificationId},
AppState, WorkspaceSettings, WorkspaceStore,
AppState, SerializedWorkspaceLocation, WorkspaceSettings, WorkspaceStore,
};
use zed::{
app_menus, build_window_options, derive_paths_with_position, handle_cli_connection,
@ -868,15 +869,41 @@ async fn restore_or_create_workspace(
) -> Result<()> {
if let Some(locations) = restorable_workspace_locations(cx, &app_state).await {
for location in locations {
cx.update(|cx| {
workspace::open_paths(
location.paths().as_ref(),
app_state.clone(),
workspace::OpenOptions::default(),
cx,
)
})?
.await?;
match location {
SerializedWorkspaceLocation::Local(location, _) => {
let task = cx.update(|cx| {
workspace::open_paths(
location.paths().as_ref(),
app_state.clone(),
workspace::OpenOptions::default(),
cx,
)
})?;
task.await?;
}
SerializedWorkspaceLocation::Ssh(ssh_project) => {
let connection_options = SshConnectionOptions {
host: ssh_project.host.clone(),
username: ssh_project.user.clone(),
port: ssh_project.port,
password: None,
};
let app_state = app_state.clone();
cx.spawn(move |mut cx| async move {
recent_projects::open_ssh_project(
connection_options,
ssh_project.paths.into_iter().map(PathBuf::from).collect(),
app_state,
workspace::OpenOptions::default(),
&mut cx,
)
.await
.log_err();
})
.detach();
}
SerializedWorkspaceLocation::DevServer(_) => {}
}
}
} else if matches!(KEY_VALUE_STORE.read_kvp(FIRST_OPEN), Ok(None)) {
cx.update(|cx| show_welcome_view(app_state, cx))?.await?;
@ -895,7 +922,7 @@ async fn restore_or_create_workspace(
pub(crate) async fn restorable_workspace_locations(
cx: &mut AsyncAppContext,
app_state: &Arc<AppState>,
) -> Option<Vec<workspace::LocalPaths>> {
) -> Option<Vec<SerializedWorkspaceLocation>> {
let mut restore_behavior = cx
.update(|cx| WorkspaceSettings::get(None, cx).restore_on_startup)
.ok()?;
@ -923,7 +950,7 @@ pub(crate) async fn restorable_workspace_locations(
match restore_behavior {
workspace::RestoreOnStartupBehavior::LastWorkspace => {
workspace::last_opened_workspace_paths()
workspace::last_opened_workspace_location()
.await
.map(|location| vec![location])
}