ssh remoting: Show error if opening connection timed out (#18401)

This shows an error if opening a connection to a remote host didn't work
in the timeout of 10s (maybe we'll need to make that configurable in the
future? for now it seems fine.)

![screenshot-2024-09-26-18 01
07@2x](https://github.com/user-attachments/assets/cbfa0e9f-9c29-4b6c-bade-07fdd7393c9d)


Release Notes:

- N/A

---------

Co-authored-by: Bennet <bennet@zed.dev>
Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
Thorsten Ball 2024-09-27 09:31:45 +02:00 committed by GitHub
parent 8559731e0d
commit 5199135b54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 115 additions and 41 deletions

View file

@ -16,8 +16,9 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsSources};
use ui::{
h_flex, v_flex, FluentBuilder as _, Icon, IconName, IconSize, InteractiveElement, IntoElement,
Label, LabelCommon, Styled, StyledExt as _, ViewContext, VisualContext, WindowContext,
h_flex, v_flex, Color, FluentBuilder as _, Icon, IconName, IconSize, InteractiveElement,
IntoElement, Label, LabelCommon, Styled, StyledExt as _, ViewContext, VisualContext,
WindowContext,
};
use workspace::{AppState, ModalView, Workspace};
@ -79,6 +80,7 @@ impl Settings for SshSettings {
pub struct SshPrompt {
connection_string: SharedString,
status_message: Option<SharedString>,
error_message: Option<SharedString>,
prompt: Option<(SharedString, oneshot::Sender<Result<String>>)>,
editor: View<Editor>,
}
@ -92,6 +94,7 @@ impl SshPrompt {
Self {
connection_string,
status_message: None,
error_message: None,
prompt: None,
editor: cx.new_view(Editor::single_line),
}
@ -121,6 +124,11 @@ impl SshPrompt {
cx.notify();
}
pub fn set_error(&mut self, error_message: String, cx: &mut ViewContext<Self>) {
self.error_message = Some(error_message.into());
cx.notify();
}
pub fn confirm(&mut self, cx: &mut ViewContext<Self>) {
if let Some((_, tx)) = self.prompt.take() {
self.editor.update(cx, |editor, cx| {
@ -140,7 +148,12 @@ impl Render for SshPrompt {
.child(
h_flex()
.gap_2()
.child(
.child(if self.error_message.is_some() {
Icon::new(IconName::XCircle)
.size(IconSize::Medium)
.color(Color::Error)
.into_any_element()
} else {
Icon::new(IconName::ArrowCircle)
.size(IconSize::Medium)
.with_animation(
@ -149,16 +162,21 @@ impl Render for SshPrompt {
|icon, delta| {
icon.transform(Transformation::rotate(percentage(delta)))
},
),
)
)
.into_any_element()
})
.child(
Label::new(format!("ssh {}", self.connection_string))
.size(ui::LabelSize::Large),
),
)
.when_some(self.status_message.as_ref(), |el, status| {
el.child(Label::new(status.clone()))
.when_some(self.error_message.as_ref(), |el, error| {
el.child(Label::new(error.clone()))
})
.when(
self.error_message.is_none() && self.status_message.is_some(),
|el| el.child(Label::new(self.status_message.clone().unwrap())),
)
.when_some(self.prompt.as_ref(), |el, prompt| {
el.child(Label::new(prompt.0.clone()))
.child(self.editor.clone())
@ -238,6 +256,10 @@ impl remote::SshClientDelegate for SshClientDelegate {
self.update_status(status, cx)
}
fn set_error(&self, error: String, cx: &mut AsyncAppContext) {
self.update_error(error, cx)
}
fn get_server_binary(
&self,
platform: SshPlatform,
@ -270,6 +292,16 @@ impl SshClientDelegate {
.ok();
}
fn update_error(&self, error: String, cx: &mut AsyncAppContext) {
self.window
.update(cx, |_, cx| {
self.ui.update(cx, |modal, cx| {
modal.set_error(error, cx);
})
})
.ok();
}
async fn get_server_binary_impl(
&self,
platform: SshPlatform,
@ -388,7 +420,7 @@ pub async fn open_ssh_project(
})?
};
let result = window
let session = window
.update(cx, |workspace, cx| {
cx.activate_window();
workspace.toggle_modal(cx, |cx| SshConnectionModal::new(&connection_options, cx));
@ -400,12 +432,7 @@ pub async fn open_ssh_project(
.clone();
connect_over_ssh(connection_options.clone(), ui, cx)
})?
.await;
if result.is_err() {
window.update(cx, |_, cx| cx.remove_window()).ok();
}
let session = result?;
.await?;
cx.update(|cx| {
workspace::open_ssh_project(window, connection_options, session, app_state, paths, cx)