diff --git a/src/commands/edge_app.rs b/src/commands/edge_app.rs index 8fc7405..70a8607 100644 --- a/src/commands/edge_app.rs +++ b/src/commands/edge_app.rs @@ -391,42 +391,32 @@ impl EdgeAppCommand { address_shared.lock().unwrap().as_ref().unwrap() ); - if let Err(e) = self.open_browser( - &format!("{}/index.html", address_shared.lock().unwrap().as_ref().unwrap()), - ) { - eprintln!("{}", e); + #[cfg(target_os = "macos")] + { + let _ = std::process::Command::new("open") + .arg(format!("{}/index.html", address_shared.lock().unwrap().as_ref().unwrap())) + .output(); } - loop { - tokio::time::sleep(std::time::Duration::from_secs(3600)).await; + #[cfg(target_os = "linux")] + { + let _ = std::process::Command::new("xdg-open") + .arg(format!("{}/index.html", address_shared.lock().unwrap().as_ref().unwrap())) + .output(); } - }); - Ok(()) - } - - fn open_browser(&self, address: &str) -> Result<(), CommandError> { - let command = match std::env::consts::OS { - "macos" => "open", - "windows" => "start", - "linux" => "xdg-open", - _ => { - return Err(CommandError::OpenBrowserError( - "Unsupported OS to open browser".to_string() - )) + #[cfg(target_os = "windows")] + { + let _ = std::process::Command::new("cmd") + .arg("/C") + .arg(format!("start {}/index.html", address_shared.lock().unwrap().as_ref().unwrap())) + .output(); } - }; - - let output = std::process::Command::new(command) - .arg(address) - .output() - .expect("Failed to open browser"); - if !output.status.success() { - return Err(CommandError::OpenBrowserError( - format!("Failed to open browser: {}", str::from_utf8(&output.stderr).unwrap()) - )); - } + loop { + tokio::time::sleep(std::time::Duration::from_secs(3600)).await; + } + }); Ok(()) } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 918f38d..e144c54 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -126,8 +126,6 @@ pub enum CommandError { SettingDoesNotExist(String), #[error("Wrong setting name: {0}.")] WrongSettingName(String), - #[error("Failed to open browser")] - OpenBrowserError(String), } pub fn get(