ssh_connections.rs

  1use std::{path::PathBuf, sync::Arc, time::Duration};
  2
  3use anyhow::{anyhow, Result};
  4use auto_update::AutoUpdater;
  5use editor::Editor;
  6use futures::channel::oneshot;
  7use gpui::{
  8    percentage, Animation, AnimationExt, AnyWindowHandle, AsyncAppContext, DismissEvent,
  9    EventEmitter, FocusableView, ParentElement as _, PromptLevel, Render, SemanticVersion,
 10    SharedString, Task, TextStyleRefinement, Transformation, View, WeakView,
 11};
 12use gpui::{AppContext, Model};
 13
 14use language::CursorShape;
 15use markdown::{Markdown, MarkdownStyle};
 16use release_channel::{AppVersion, ReleaseChannel};
 17use remote::ssh_session::ServerBinary;
 18use remote::{SshConnectionOptions, SshPlatform, SshRemoteClient};
 19use schemars::JsonSchema;
 20use serde::{Deserialize, Serialize};
 21use settings::{Settings, SettingsSources};
 22use theme::ThemeSettings;
 23use ui::{
 24    prelude::*, ActiveTheme, Color, Icon, IconName, IconSize, InteractiveElement, IntoElement,
 25    Label, LabelCommon, Styled, ViewContext, VisualContext, WindowContext,
 26};
 27use workspace::{AppState, ModalView, Workspace};
 28
 29#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
 30pub struct RemoteServerSettings {
 31    pub download_on_host: Option<bool>,
 32}
 33
 34#[derive(Deserialize)]
 35pub struct SshSettings {
 36    pub ssh_connections: Option<Vec<SshConnection>>,
 37    pub remote_server: Option<RemoteServerSettings>,
 38}
 39
 40impl SshSettings {
 41    pub fn ssh_connections(&self) -> impl Iterator<Item = SshConnection> {
 42        self.ssh_connections.clone().into_iter().flatten()
 43    }
 44
 45    pub fn args_for(
 46        &self,
 47        host: &str,
 48        port: Option<u16>,
 49        user: &Option<String>,
 50    ) -> Option<Vec<String>> {
 51        self.ssh_connections()
 52            .filter_map(|conn| {
 53                if conn.host == host && &conn.username == user && conn.port == port {
 54                    Some(conn.args)
 55                } else {
 56                    None
 57                }
 58            })
 59            .next()
 60    }
 61
 62    pub fn nickname_for(
 63        &self,
 64        host: &str,
 65        port: Option<u16>,
 66        user: &Option<String>,
 67    ) -> Option<SharedString> {
 68        self.ssh_connections()
 69            .filter_map(|conn| {
 70                if conn.host == host && &conn.username == user && conn.port == port {
 71                    Some(conn.nickname)
 72                } else {
 73                    None
 74                }
 75            })
 76            .next()
 77            .flatten()
 78    }
 79}
 80
 81#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
 82pub struct SshConnection {
 83    pub host: SharedString,
 84    #[serde(skip_serializing_if = "Option::is_none")]
 85    pub username: Option<String>,
 86    #[serde(skip_serializing_if = "Option::is_none")]
 87    pub port: Option<u16>,
 88    pub projects: Vec<SshProject>,
 89    /// Name to use for this server in UI.
 90    #[serde(skip_serializing_if = "Option::is_none")]
 91    pub nickname: Option<SharedString>,
 92    #[serde(skip_serializing_if = "Vec::is_empty")]
 93    #[serde(default)]
 94    pub args: Vec<String>,
 95}
 96
 97impl From<SshConnection> for SshConnectionOptions {
 98    fn from(val: SshConnection) -> Self {
 99        SshConnectionOptions {
100            host: val.host.into(),
101            username: val.username,
102            port: val.port,
103            password: None,
104            args: Some(val.args),
105        }
106    }
107}
108
109#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
110pub struct SshProject {
111    pub paths: Vec<String>,
112}
113
114#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
115pub struct RemoteSettingsContent {
116    pub ssh_connections: Option<Vec<SshConnection>>,
117    pub remote_server: Option<RemoteServerSettings>,
118}
119
120impl Settings for SshSettings {
121    const KEY: Option<&'static str> = None;
122
123    type FileContent = RemoteSettingsContent;
124
125    fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
126        sources.json_merge()
127    }
128}
129
130pub struct SshPrompt {
131    connection_string: SharedString,
132    nickname: Option<SharedString>,
133    status_message: Option<SharedString>,
134    prompt: Option<(View<Markdown>, oneshot::Sender<Result<String>>)>,
135    cancellation: Option<oneshot::Sender<()>>,
136    editor: View<Editor>,
137}
138
139impl Drop for SshPrompt {
140    fn drop(&mut self) {
141        if let Some(cancel) = self.cancellation.take() {
142            cancel.send(()).ok();
143        }
144    }
145}
146
147pub struct SshConnectionModal {
148    pub(crate) prompt: View<SshPrompt>,
149    paths: Vec<PathBuf>,
150    finished: bool,
151}
152
153impl SshPrompt {
154    pub(crate) fn new(
155        connection_options: &SshConnectionOptions,
156        nickname: Option<SharedString>,
157        cx: &mut ViewContext<Self>,
158    ) -> Self {
159        let connection_string = connection_options.connection_string().into();
160
161        Self {
162            connection_string,
163            nickname,
164            editor: cx.new_view(Editor::single_line),
165            status_message: None,
166            cancellation: None,
167            prompt: None,
168        }
169    }
170
171    pub fn set_cancellation_tx(&mut self, tx: oneshot::Sender<()>) {
172        self.cancellation = Some(tx);
173    }
174
175    pub fn set_prompt(
176        &mut self,
177        prompt: String,
178        tx: oneshot::Sender<Result<String>>,
179        cx: &mut ViewContext<Self>,
180    ) {
181        let theme = ThemeSettings::get_global(cx);
182
183        let mut text_style = cx.text_style();
184        let refinement = TextStyleRefinement {
185            font_family: Some(theme.buffer_font.family.clone()),
186            font_size: Some(theme.buffer_font_size.into()),
187            color: Some(cx.theme().colors().editor_foreground),
188            background_color: Some(gpui::transparent_black()),
189            ..Default::default()
190        };
191
192        text_style.refine(&refinement);
193        self.editor.update(cx, |editor, cx| {
194            if prompt.contains("yes/no") {
195                editor.set_masked(false, cx);
196            } else {
197                editor.set_masked(true, cx);
198            }
199            editor.set_text_style_refinement(refinement);
200            editor.set_cursor_shape(CursorShape::Block, cx);
201        });
202        let markdown_style = MarkdownStyle {
203            base_text_style: text_style,
204            selection_background_color: cx.theme().players().local().selection,
205            ..Default::default()
206        };
207        let markdown = cx.new_view(|cx| Markdown::new_text(prompt, markdown_style, None, cx, None));
208        self.prompt = Some((markdown, tx));
209        self.status_message.take();
210        cx.focus_view(&self.editor);
211        cx.notify();
212    }
213
214    pub fn set_status(&mut self, status: Option<String>, cx: &mut ViewContext<Self>) {
215        self.status_message = status.map(|s| s.into());
216        cx.notify();
217    }
218
219    pub fn confirm(&mut self, cx: &mut ViewContext<Self>) {
220        if let Some((_, tx)) = self.prompt.take() {
221            self.status_message = Some("Connecting".into());
222            self.editor.update(cx, |editor, cx| {
223                tx.send(Ok(editor.text(cx))).ok();
224                editor.clear(cx);
225            });
226        }
227    }
228}
229
230impl Render for SshPrompt {
231    fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
232        let cx = cx.window_context();
233
234        v_flex()
235            .key_context("PasswordPrompt")
236            .py_2()
237            .px_3()
238            .size_full()
239            .text_buffer(cx)
240            .when_some(self.status_message.clone(), |el, status_message| {
241                el.child(
242                    h_flex()
243                        .gap_1()
244                        .child(
245                            Icon::new(IconName::ArrowCircle)
246                                .size(IconSize::Medium)
247                                .with_animation(
248                                    "arrow-circle",
249                                    Animation::new(Duration::from_secs(2)).repeat(),
250                                    |icon, delta| {
251                                        icon.transform(Transformation::rotate(percentage(delta)))
252                                    },
253                                ),
254                        )
255                        .child(
256                            div()
257                                .text_ellipsis()
258                                .overflow_x_hidden()
259                                .child(format!("{}", status_message)),
260                        ),
261                )
262            })
263            .when_some(self.prompt.as_ref(), |el, prompt| {
264                el.child(
265                    div()
266                        .size_full()
267                        .overflow_hidden()
268                        .child(prompt.0.clone())
269                        .child(self.editor.clone()),
270                )
271            })
272    }
273}
274
275impl SshConnectionModal {
276    pub(crate) fn new(
277        connection_options: &SshConnectionOptions,
278        paths: Vec<PathBuf>,
279        nickname: Option<SharedString>,
280        cx: &mut ViewContext<Self>,
281    ) -> Self {
282        Self {
283            prompt: cx.new_view(|cx| SshPrompt::new(connection_options, nickname, cx)),
284            finished: false,
285            paths,
286        }
287    }
288
289    fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
290        self.prompt.update(cx, |prompt, cx| prompt.confirm(cx))
291    }
292
293    pub fn finished(&mut self, cx: &mut ViewContext<Self>) {
294        self.finished = true;
295        cx.emit(DismissEvent);
296    }
297
298    fn dismiss(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
299        if let Some(tx) = self
300            .prompt
301            .update(cx, |prompt, _cx| prompt.cancellation.take())
302        {
303            tx.send(()).ok();
304        }
305        self.finished(cx);
306    }
307}
308
309pub(crate) struct SshConnectionHeader {
310    pub(crate) connection_string: SharedString,
311    pub(crate) paths: Vec<PathBuf>,
312    pub(crate) nickname: Option<SharedString>,
313}
314
315impl RenderOnce for SshConnectionHeader {
316    fn render(self, cx: &mut WindowContext) -> impl IntoElement {
317        let theme = cx.theme();
318
319        let mut header_color = theme.colors().text;
320        header_color.fade_out(0.96);
321
322        let (main_label, meta_label) = if let Some(nickname) = self.nickname {
323            (nickname, Some(format!("({})", self.connection_string)))
324        } else {
325            (self.connection_string, None)
326        };
327
328        h_flex()
329            .px(Spacing::XLarge.rems(cx))
330            .pt(Spacing::Large.rems(cx))
331            .pb(Spacing::Small.rems(cx))
332            .rounded_t_md()
333            .w_full()
334            .gap_1p5()
335            .child(Icon::new(IconName::Server).size(IconSize::XSmall))
336            .child(
337                h_flex()
338                    .gap_1()
339                    .overflow_x_hidden()
340                    .child(
341                        div()
342                            .max_w_96()
343                            .overflow_x_hidden()
344                            .text_ellipsis()
345                            .child(Headline::new(main_label).size(HeadlineSize::XSmall)),
346                    )
347                    .children(
348                        meta_label.map(|label| {
349                            Label::new(label).color(Color::Muted).size(LabelSize::Small)
350                        }),
351                    )
352                    .child(div().overflow_x_hidden().text_ellipsis().children(
353                        self.paths.into_iter().map(|path| {
354                            Label::new(path.to_string_lossy().to_string())
355                                .size(LabelSize::Small)
356                                .color(Color::Muted)
357                        }),
358                    )),
359            )
360    }
361}
362
363impl Render for SshConnectionModal {
364    fn render(&mut self, cx: &mut ui::ViewContext<Self>) -> impl ui::IntoElement {
365        let nickname = self.prompt.read(cx).nickname.clone();
366        let connection_string = self.prompt.read(cx).connection_string.clone();
367
368        let theme = cx.theme().clone();
369        let body_color = theme.colors().editor_background;
370
371        v_flex()
372            .elevation_3(cx)
373            .w(rems(34.))
374            .border_1()
375            .border_color(theme.colors().border)
376            .key_context("SshConnectionModal")
377            .track_focus(&self.focus_handle(cx))
378            .on_action(cx.listener(Self::dismiss))
379            .on_action(cx.listener(Self::confirm))
380            .child(
381                SshConnectionHeader {
382                    paths: self.paths.clone(),
383                    connection_string,
384                    nickname,
385                }
386                .render(cx),
387            )
388            .child(
389                div()
390                    .w_full()
391                    .rounded_b_lg()
392                    .bg(body_color)
393                    .border_t_1()
394                    .border_color(theme.colors().border_variant)
395                    .child(self.prompt.clone()),
396            )
397    }
398}
399
400impl FocusableView for SshConnectionModal {
401    fn focus_handle(&self, cx: &gpui::AppContext) -> gpui::FocusHandle {
402        self.prompt.read(cx).editor.focus_handle(cx)
403    }
404}
405
406impl EventEmitter<DismissEvent> for SshConnectionModal {}
407
408impl ModalView for SshConnectionModal {
409    fn on_before_dismiss(&mut self, _: &mut ViewContext<Self>) -> workspace::DismissDecision {
410        return workspace::DismissDecision::Dismiss(self.finished);
411    }
412
413    fn fade_out_background(&self) -> bool {
414        true
415    }
416}
417
418#[derive(Clone)]
419pub struct SshClientDelegate {
420    window: AnyWindowHandle,
421    ui: WeakView<SshPrompt>,
422    known_password: Option<String>,
423}
424
425impl remote::SshClientDelegate for SshClientDelegate {
426    fn ask_password(
427        &self,
428        prompt: String,
429        cx: &mut AsyncAppContext,
430    ) -> oneshot::Receiver<Result<String>> {
431        let (tx, rx) = oneshot::channel();
432        let mut known_password = self.known_password.clone();
433        if let Some(password) = known_password.take() {
434            tx.send(Ok(password)).ok();
435        } else {
436            self.window
437                .update(cx, |_, cx| {
438                    self.ui.update(cx, |modal, cx| {
439                        modal.set_prompt(prompt, tx, cx);
440                    })
441                })
442                .ok();
443        }
444        rx
445    }
446
447    fn set_status(&self, status: Option<&str>, cx: &mut AsyncAppContext) {
448        self.update_status(status, cx)
449    }
450
451    fn get_server_binary(
452        &self,
453        platform: SshPlatform,
454        cx: &mut AsyncAppContext,
455    ) -> oneshot::Receiver<Result<(ServerBinary, SemanticVersion)>> {
456        let (tx, rx) = oneshot::channel();
457        let this = self.clone();
458        cx.spawn(|mut cx| async move {
459            tx.send(this.get_server_binary_impl(platform, &mut cx).await)
460                .ok();
461        })
462        .detach();
463        rx
464    }
465
466    fn remote_server_binary_path(
467        &self,
468        platform: SshPlatform,
469        cx: &mut AsyncAppContext,
470    ) -> Result<PathBuf> {
471        let release_channel = cx.update(|cx| ReleaseChannel::global(cx))?;
472        Ok(paths::remote_server_dir_relative().join(format!(
473            "zed-remote-server-{}-{}-{}",
474            release_channel.dev_name(),
475            platform.os,
476            platform.arch
477        )))
478    }
479}
480
481impl SshClientDelegate {
482    fn update_status(&self, status: Option<&str>, cx: &mut AsyncAppContext) {
483        self.window
484            .update(cx, |_, cx| {
485                self.ui.update(cx, |modal, cx| {
486                    modal.set_status(status.map(|s| s.to_string()), cx);
487                })
488            })
489            .ok();
490    }
491
492    async fn get_server_binary_impl(
493        &self,
494        platform: SshPlatform,
495        cx: &mut AsyncAppContext,
496    ) -> Result<(ServerBinary, SemanticVersion)> {
497        let (version, release_channel, download_binary_on_host) = cx.update(|cx| {
498            let version = AppVersion::global(cx);
499            let channel = ReleaseChannel::global(cx);
500
501            let ssh_settings = SshSettings::get_global(cx);
502            let download_binary_on_host = ssh_settings
503                .remote_server
504                .as_ref()
505                .and_then(|server| server.download_on_host)
506                .unwrap_or(false);
507            (version, channel, download_binary_on_host)
508        })?;
509
510        // In dev mode, build the remote server binary from source
511        #[cfg(debug_assertions)]
512        if release_channel == ReleaseChannel::Dev {
513            let result = self.build_local(cx, platform, version).await?;
514            // Fall through to a remote binary if we're not able to compile a local binary
515            if let Some((path, version)) = result {
516                return Ok((ServerBinary::LocalBinary(path), version));
517            }
518        }
519
520        // For nightly channel, always get latest
521        let current_version = if release_channel == ReleaseChannel::Nightly {
522            None
523        } else {
524            Some(version)
525        };
526
527        self.update_status(
528            Some(&format!("Checking remote server release {}", version)),
529            cx,
530        );
531
532        if download_binary_on_host {
533            let (request_url, request_body) = AutoUpdater::get_remote_server_release_url(
534                platform.os,
535                platform.arch,
536                release_channel,
537                current_version,
538                cx,
539            )
540            .await
541            .map_err(|e| {
542                anyhow!(
543                    "Failed to get remote server binary download url (version: {}, os: {}, arch: {}): {}",
544                    version,
545                    platform.os,
546                    platform.arch,
547                    e
548                )
549            })?;
550
551            Ok((
552                ServerBinary::ReleaseUrl {
553                    url: request_url,
554                    body: request_body,
555                },
556                version,
557            ))
558        } else {
559            let binary_path = AutoUpdater::download_remote_server_release(
560                platform.os,
561                platform.arch,
562                release_channel,
563                current_version,
564                cx,
565            )
566            .await
567            .map_err(|e| {
568                anyhow!(
569                    "Failed to download remote server binary (version: {}, os: {}, arch: {}): {}",
570                    version,
571                    platform.os,
572                    platform.arch,
573                    e
574                )
575            })?;
576
577            Ok((ServerBinary::LocalBinary(binary_path), version))
578        }
579    }
580
581    #[cfg(debug_assertions)]
582    async fn build_local(
583        &self,
584        cx: &mut AsyncAppContext,
585        platform: SshPlatform,
586        version: gpui::SemanticVersion,
587    ) -> Result<Option<(PathBuf, gpui::SemanticVersion)>> {
588        use smol::process::{Command, Stdio};
589
590        async fn run_cmd(command: &mut Command) -> Result<()> {
591            let output = command
592                .kill_on_drop(true)
593                .stderr(Stdio::inherit())
594                .output()
595                .await?;
596            if !output.status.success() {
597                Err(anyhow!("Failed to run command: {:?}", command))?;
598            }
599            Ok(())
600        }
601
602        if platform.arch == std::env::consts::ARCH && platform.os == std::env::consts::OS {
603            self.update_status(Some("Building remote server binary from source"), cx);
604            log::info!("building remote server binary from source");
605            run_cmd(Command::new("cargo").args([
606                "build",
607                "--package",
608                "remote_server",
609                "--features",
610                "debug-embed",
611                "--target-dir",
612                "target/remote_server",
613            ]))
614            .await?;
615
616            self.update_status(Some("Compressing binary"), cx);
617
618            run_cmd(Command::new("gzip").args([
619                "-9",
620                "-f",
621                "target/remote_server/debug/remote_server",
622            ]))
623            .await?;
624
625            let path = std::env::current_dir()?.join("target/remote_server/debug/remote_server.gz");
626            return Ok(Some((path, version)));
627        } else if let Some(triple) = platform.triple() {
628            smol::fs::create_dir_all("target/remote_server").await?;
629
630            self.update_status(Some("Installing cross.rs for cross-compilation"), cx);
631            log::info!("installing cross");
632            run_cmd(Command::new("cargo").args([
633                "install",
634                "cross",
635                "--git",
636                "https://github.com/cross-rs/cross",
637            ]))
638            .await?;
639
640            self.update_status(
641                Some(&format!(
642                    "Building remote server binary from source for {}",
643                    &triple
644                )),
645                cx,
646            );
647            log::info!("building remote server binary from source for {}", &triple);
648            run_cmd(
649                Command::new("cross")
650                    .args([
651                        "build",
652                        "--package",
653                        "remote_server",
654                        "--features",
655                        "debug-embed",
656                        "--target-dir",
657                        "target/remote_server",
658                        "--target",
659                        &triple,
660                    ])
661                    .env(
662                        "CROSS_CONTAINER_OPTS",
663                        "--mount type=bind,src=./target,dst=/app/target",
664                    ),
665            )
666            .await?;
667
668            self.update_status(Some("Compressing binary"), cx);
669
670            run_cmd(Command::new("gzip").args([
671                "-9",
672                "-f",
673                &format!("target/remote_server/{}/debug/remote_server", triple),
674            ]))
675            .await?;
676
677            let path = std::env::current_dir()?.join(format!(
678                "target/remote_server/{}/debug/remote_server.gz",
679                triple
680            ));
681
682            return Ok(Some((path, version)));
683        } else {
684            return Ok(None);
685        }
686    }
687}
688
689pub fn connect_over_ssh(
690    unique_identifier: String,
691    connection_options: SshConnectionOptions,
692    ui: View<SshPrompt>,
693    cx: &mut WindowContext,
694) -> Task<Result<Option<Model<SshRemoteClient>>>> {
695    let window = cx.window_handle();
696    let known_password = connection_options.password.clone();
697    let (tx, rx) = oneshot::channel();
698    ui.update(cx, |ui, _cx| ui.set_cancellation_tx(tx));
699
700    remote::SshRemoteClient::new(
701        unique_identifier,
702        connection_options,
703        rx,
704        Arc::new(SshClientDelegate {
705            window,
706            ui: ui.downgrade(),
707            known_password,
708        }),
709        cx,
710    )
711}
712
713pub async fn open_ssh_project(
714    connection_options: SshConnectionOptions,
715    paths: Vec<PathBuf>,
716    app_state: Arc<AppState>,
717    open_options: workspace::OpenOptions,
718    nickname: Option<SharedString>,
719    cx: &mut AsyncAppContext,
720) -> Result<()> {
721    let window = if let Some(window) = open_options.replace_window {
722        window
723    } else {
724        let options = cx.update(|cx| (app_state.build_window_options)(None, cx))?;
725        cx.open_window(options, |cx| {
726            let project = project::Project::local(
727                app_state.client.clone(),
728                app_state.node_runtime.clone(),
729                app_state.user_store.clone(),
730                app_state.languages.clone(),
731                app_state.fs.clone(),
732                None,
733                cx,
734            );
735            cx.new_view(|cx| Workspace::new(None, project, app_state.clone(), cx))
736        })?
737    };
738
739    loop {
740        let (cancel_tx, cancel_rx) = oneshot::channel();
741        let delegate = window.update(cx, {
742            let connection_options = connection_options.clone();
743            let nickname = nickname.clone();
744            let paths = paths.clone();
745            move |workspace, cx| {
746                cx.activate_window();
747                workspace.toggle_modal(cx, |cx| {
748                    SshConnectionModal::new(&connection_options, paths, nickname.clone(), cx)
749                });
750
751                let ui = workspace
752                    .active_modal::<SshConnectionModal>(cx)?
753                    .read(cx)
754                    .prompt
755                    .clone();
756
757                ui.update(cx, |ui, _cx| {
758                    ui.set_cancellation_tx(cancel_tx);
759                });
760
761                Some(Arc::new(SshClientDelegate {
762                    window: cx.window_handle(),
763                    ui: ui.downgrade(),
764                    known_password: connection_options.password.clone(),
765                }))
766            }
767        })?;
768
769        let Some(delegate) = delegate else { break };
770
771        let did_open_ssh_project = cx
772            .update(|cx| {
773                workspace::open_ssh_project(
774                    window,
775                    connection_options.clone(),
776                    cancel_rx,
777                    delegate.clone(),
778                    app_state.clone(),
779                    paths.clone(),
780                    cx,
781                )
782            })?
783            .await;
784
785        window
786            .update(cx, |workspace, cx| {
787                if let Some(ui) = workspace.active_modal::<SshConnectionModal>(cx) {
788                    ui.update(cx, |modal, cx| modal.finished(cx))
789                }
790            })
791            .ok();
792
793        if let Err(e) = did_open_ssh_project {
794            log::error!("Failed to open project: {:?}", e);
795            let response = window
796                .update(cx, |_, cx| {
797                    cx.prompt(
798                        PromptLevel::Critical,
799                        "Failed to connect over SSH",
800                        Some(&e.to_string()),
801                        &["Retry", "Ok"],
802                    )
803                })?
804                .await;
805
806            if response == Ok(0) {
807                continue;
808            }
809        }
810
811        break;
812    }
813
814    // Already showed the error to the user
815    Ok(())
816}