Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edits: 'edge-app run' open in browser #170

Merged
merged 8 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
rusko124 marked this conversation as resolved.
Show resolved Hide resolved
_ => {
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
Loading