Skip to content

Commit

Permalink
Revert "Edits after review"
Browse files Browse the repository at this point in the history
This reverts commit 4d1b20c.
  • Loading branch information
rusko124 committed Jul 3, 2024
1 parent 18cf73a commit 6fa4293
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
50 changes: 20 additions & 30 deletions src/commands/edge_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
2 changes: 0 additions & 2 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6fa4293

Please sign in to comment.