From 0c0a16df379c21146b3edd8823190013410f55b9 Mon Sep 17 00:00:00 2001 From: stack72 Date: Fri, 25 Aug 2023 00:09:36 +0300 Subject: [PATCH] fix(si): Change the si launch command to use xdg open functionality --- lib/si-cli/src/cmd/launch.rs | 22 ++++++++++++++++------ lib/si-cli/src/lib.rs | 2 ++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/si-cli/src/cmd/launch.rs b/lib/si-cli/src/cmd/launch.rs index 5982a33133..7d45f51f21 100644 --- a/lib/si-cli/src/cmd/launch.rs +++ b/lib/si-cli/src/cmd/launch.rs @@ -2,8 +2,9 @@ use crate::key_management::get_user_email; use crate::state::AppState; use crate::{CliResult, SiCliError}; use indicatif::{ProgressBar, ProgressStyle}; -use std::thread; +use std::process::Command; use std::time::Duration; +use std::{env, thread}; impl AppState { pub async fn launch(&self, launch_metrics: bool) -> CliResult<()> { @@ -28,13 +29,22 @@ async fn invoke(launch_metrics: bool, web_host: String, web_port: u32) -> CliRes check_sdf().await?; } - println!("Opening URL: {}", path); - match open::that(path.clone()) { - Ok(()) => Ok(()), - Err(_err) => Err(SiCliError::FailToLaunch(path)), + let output = if cfg!(target_os = "macos") { + Command::new("open").arg(path.clone()).output() + } else if cfg!(target_os = "linux") { + Command::new("xdg-open").arg(path.clone()).output() + } else { + // This should NEVER get called but I added it in here just incase + return Err(SiCliError::UnsupportedOperatingSystem( + env::consts::OS.to_string(), + )); + }; + + if let Err(_err) = output { + return Err(SiCliError::FailToLaunch(path)); } - .expect("issue opening url"); + println!("Successfully opened URL: {}", path); Ok(()) } diff --git a/lib/si-cli/src/lib.rs b/lib/si-cli/src/lib.rs index 42671b297b..a1759a1790 100644 --- a/lib/si-cli/src/lib.rs +++ b/lib/si-cli/src/lib.rs @@ -49,6 +49,8 @@ pub enum SiCliError { UnableToFetchContainersUpdate(u16), #[error("unable to fetch si update, status = {0}")] UnableToFetchSiUpdate(u16), + #[error("unsupported operating system: {0}")] + UnsupportedOperatingSystem(String), #[error("env var: {0}")] Var(#[from] VarError), #[error("web portal is currently offline - please check that the system is running")]