Skip to content

Commit

Permalink
Edits: 'edge-app run' open in browser (#170)
Browse files Browse the repository at this point in the history
* Edits: 'edge-app run' open in browser

* Edits after review

* Attempt to fix lint

* Revert "Edits after review"

This reverts commit 4d1b20c.

* Attempt to fix lint

* Revert "Revert "Edits after review""

This reverts commit 6fa4293.

* Fix: clippy warning

* Fix: linter warning
  • Loading branch information
rusko124 authored Jul 3, 2024
1 parent c8cbb55 commit 1ffa4ea
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ jobs:
lint:
name: Lint code base
runs-on: ubuntu-latest

permissions:
contents: 'read'
checks: 'write'
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
34 changes: 34 additions & 0 deletions src/commands/edge_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,13 @@ 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);
}

loop {
tokio::time::sleep(std::time::Duration::from_secs(3600)).await;
}
Expand All @@ -399,6 +406,33 @@ 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
1 change: 1 addition & 0 deletions src/commands/edge_app_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub async fn run_server(
}

#[derive(Debug)]
#[allow(dead_code)]
struct WarpError(#[allow(dead_code)] anyhow::Error);

impl Reject for WarpError {}
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 1ffa4ea

Please sign in to comment.