Make closing the SSH modal equivalent to cancelling the SSH connection task (#19568)
TODO: - [x] Fix focus not being on the modal initially Release Notes: - N/A --------- Co-authored-by: Trace <violet.white.batt@gmail.com>
This commit is contained in:
parent
f951410ef0
commit
33197608ed
5 changed files with 108 additions and 56 deletions
|
@ -547,7 +547,7 @@ impl RemoteServerProjects {
|
|||
})
|
||||
.ok();
|
||||
|
||||
let Some(session) = session else {
|
||||
let Some(Some(session)) = session else {
|
||||
workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
let weak = cx.view().downgrade();
|
||||
|
@ -1071,7 +1071,7 @@ impl RemoteServerProjects {
|
|||
);
|
||||
|
||||
cx.spawn(|mut cx| async move {
|
||||
if confirmation.await.ok() == Some(0) {
|
||||
if confirmation.await.ok() == Some(1) {
|
||||
remote_servers
|
||||
.update(&mut cx, |this, cx| {
|
||||
this.delete_ssh_server(index, cx);
|
||||
|
|
|
@ -124,6 +124,7 @@ pub struct SshPrompt {
|
|||
nickname: Option<SharedString>,
|
||||
status_message: Option<SharedString>,
|
||||
prompt: Option<(View<Markdown>, oneshot::Sender<Result<String>>)>,
|
||||
cancellation: Option<oneshot::Sender<()>>,
|
||||
editor: View<Editor>,
|
||||
}
|
||||
|
||||
|
@ -142,12 +143,17 @@ impl SshPrompt {
|
|||
Self {
|
||||
connection_string,
|
||||
nickname,
|
||||
status_message: None,
|
||||
prompt: None,
|
||||
editor: cx.new_view(Editor::single_line),
|
||||
status_message: None,
|
||||
cancellation: None,
|
||||
prompt: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_cancellation_tx(&mut self, tx: oneshot::Sender<()>) {
|
||||
self.cancellation = Some(tx);
|
||||
}
|
||||
|
||||
pub fn set_prompt(
|
||||
&mut self,
|
||||
prompt: String,
|
||||
|
@ -270,7 +276,13 @@ impl SshConnectionModal {
|
|||
}
|
||||
|
||||
fn dismiss(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
|
||||
cx.emit(DismissEvent);
|
||||
if let Some(tx) = self
|
||||
.prompt
|
||||
.update(cx, |prompt, _cx| prompt.cancellation.take())
|
||||
{
|
||||
tx.send(()).ok();
|
||||
}
|
||||
self.finished(cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,6 +334,7 @@ impl Render for SshConnectionModal {
|
|||
.w(rems(34.))
|
||||
.border_1()
|
||||
.border_color(theme.colors().border)
|
||||
.key_context("SshConnectionModal")
|
||||
.track_focus(&self.focus_handle(cx))
|
||||
.on_action(cx.listener(Self::dismiss))
|
||||
.on_action(cx.listener(Self::confirm))
|
||||
|
@ -486,7 +499,11 @@ impl SshClientDelegate {
|
|||
use smol::process::{Command, Stdio};
|
||||
|
||||
async fn run_cmd(command: &mut Command) -> Result<()> {
|
||||
let output = command.stderr(Stdio::inherit()).output().await?;
|
||||
let output = command
|
||||
.kill_on_drop(true)
|
||||
.stderr(Stdio::inherit())
|
||||
.output()
|
||||
.await?;
|
||||
if !output.status.success() {
|
||||
Err(anyhow::anyhow!("failed to run command: {:?}", command))?;
|
||||
}
|
||||
|
@ -585,13 +602,16 @@ pub fn connect_over_ssh(
|
|||
connection_options: SshConnectionOptions,
|
||||
ui: View<SshPrompt>,
|
||||
cx: &mut WindowContext,
|
||||
) -> Task<Result<Model<SshRemoteClient>>> {
|
||||
) -> Task<Result<Option<Model<SshRemoteClient>>>> {
|
||||
let window = cx.window_handle();
|
||||
let known_password = connection_options.password.clone();
|
||||
let (tx, rx) = oneshot::channel();
|
||||
ui.update(cx, |ui, _cx| ui.set_cancellation_tx(tx));
|
||||
|
||||
remote::SshRemoteClient::new(
|
||||
unique_identifier,
|
||||
connection_options,
|
||||
rx,
|
||||
Arc::new(SshClientDelegate {
|
||||
window,
|
||||
ui,
|
||||
|
@ -628,6 +648,7 @@ pub async fn open_ssh_project(
|
|||
};
|
||||
|
||||
loop {
|
||||
let (cancel_tx, cancel_rx) = oneshot::channel();
|
||||
let delegate = window.update(cx, {
|
||||
let connection_options = connection_options.clone();
|
||||
let nickname = nickname.clone();
|
||||
|
@ -636,26 +657,33 @@ pub async fn open_ssh_project(
|
|||
workspace.toggle_modal(cx, |cx| {
|
||||
SshConnectionModal::new(&connection_options, nickname.clone(), cx)
|
||||
});
|
||||
|
||||
let ui = workspace
|
||||
.active_modal::<SshConnectionModal>(cx)
|
||||
.unwrap()
|
||||
.active_modal::<SshConnectionModal>(cx)?
|
||||
.read(cx)
|
||||
.prompt
|
||||
.clone();
|
||||
|
||||
Arc::new(SshClientDelegate {
|
||||
ui.update(cx, |ui, _cx| {
|
||||
ui.set_cancellation_tx(cancel_tx);
|
||||
});
|
||||
|
||||
Some(Arc::new(SshClientDelegate {
|
||||
window: cx.window_handle(),
|
||||
ui,
|
||||
known_password: connection_options.password.clone(),
|
||||
})
|
||||
}))
|
||||
}
|
||||
})?;
|
||||
|
||||
let Some(delegate) = delegate else { break };
|
||||
|
||||
let did_open_ssh_project = cx
|
||||
.update(|cx| {
|
||||
workspace::open_ssh_project(
|
||||
window,
|
||||
connection_options.clone(),
|
||||
cancel_rx,
|
||||
delegate.clone(),
|
||||
app_state.clone(),
|
||||
paths.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue