Skip to content

Commit

Permalink
Edits after review
Browse files Browse the repository at this point in the history
  • Loading branch information
rusko124 committed Jul 2, 2024
1 parent 89f089f commit 4d1b20c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
50 changes: 30 additions & 20 deletions src/commands/edge_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,26 +391,10 @@ impl EdgeAppCommand {
address_shared.lock().unwrap().as_ref().unwrap()
);

#[cfg(target_os = "macos")]
{
let _ = std::process::Command::new("open")
.arg(format!("{}/index.html", address_shared.lock().unwrap().as_ref().unwrap()))
.output();
}

#[cfg(target_os = "linux")]
{
let _ = std::process::Command::new("xdg-open")
.arg(format!("{}/index.html", address_shared.lock().unwrap().as_ref().unwrap()))
.output();
}

#[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();
if let Err(e) = self.open_browser(
&format!("{}/index.html", address_shared.lock().unwrap().as_ref().unwrap()),
) {
eprintln!("{}", e);
}

loop {
Expand All @@ -421,6 +405,32 @@ impl EdgeAppCommand {
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()
))
}
};

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())
));
}

Ok(())
}

fn maybe_delete_missing_settings(
&self,
delete_missing_settings: Option<bool>,
Expand Down
2 changes: 2 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub enum CommandError {
SettingDoesNotExist(String),
#[error("Wrong setting name: {0}.")]
WrongSettingName(String),
#[error("Failed to open browser")]
OpenBrowserError(String),
}

pub fn get(
Expand Down

0 comments on commit 4d1b20c

Please sign in to comment.