Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1495 from cloudflare/josh/child-browser
Browse files Browse the repository at this point in the history
Change open_browser to open browser in child process
  • Loading branch information
EverlastingBugstopper authored Aug 12, 2020
2 parents 38bfa88 + a3656a9 commit ad32c7b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/terminal/browser.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
use std::process::Command;
use std::process::{Command, Stdio};

pub fn open_browser(url: &str) -> Result<(), failure::Error> {
let _output = if cfg!(target_os = "windows") {
if cfg!(target_os = "windows") {
let url_escaped = url.replace("&", "^&");
let windows_cmd = format!("start {}", url_escaped);
Command::new("cmd").args(&["/C", &windows_cmd]).output()?
Command::new("cmd")
.args(&["/C", &windows_cmd])
.stdout(Stdio::null())
.spawn()?;
} else if cfg!(target_os = "linux") {
let linux_cmd = format!(r#"xdg-open "{}""#, url);
Command::new("sh").arg("-c").arg(&linux_cmd).output()?
Command::new("sh")
.arg("-c")
.arg(&linux_cmd)
.stdout(Stdio::null())
.spawn()?;
} else {
let mac_cmd = format!(r#"open "{}""#, url);
Command::new("sh").arg("-c").arg(&mac_cmd).output()?
Command::new("sh")
.arg("-c")
.arg(&mac_cmd)
.stdout(Stdio::null())
.spawn()?;
};

Ok(())
Expand Down

0 comments on commit ad32c7b

Please sign in to comment.