diff options
author | Teddy Wing | 2017-04-13 02:53:53 +0200 |
---|---|---|
committer | Teddy Wing | 2017-04-13 02:53:53 +0200 |
commit | f7cc81ef359e8d9ecb7e4ce3b34e43d9d94e2071 (patch) | |
tree | 9c9e7cf110edccd31a645fcad83041a875a257e1 /src/main.rs | |
parent | 24bc7b9bedd0da8e664e143c468e9f1405ded2f3 (diff) | |
download | HearURL-f7cc81ef359e8d9ecb7e4ce3b34e43d9d94e2071.tar.bz2 |
main.rs: Open the stream input in Opera
Use the Mac OS X `open` command to open Opera and pass in the contents
of the TCP stream as an argument, assuming it to be a URL that should
be opened in the browser.
Only dealing with the `open` command for now. Will be extending this to
support user-customisable browsers, so that any GUI browser that can be
opened with `open` can be used.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index fcd9cfd..09dc892 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::io::{self, Write}; use std::io::prelude::*; use std::net::TcpListener; +use std::process::Command; fn open_stream() -> io::Result<()> { let listener = TcpListener::bind("127.0.0.1:34254")?; @@ -11,7 +12,14 @@ fn open_stream() -> io::Result<()> { let mut url = String::new(); stream.read_to_string(&mut url)?; - println!("{}", url); + Command::new("open") + .arg("-a") + .arg("Opera") + + // Trim the trailing newline, otherwise this doesn't + // work + .arg(&url.trim_right()) + .spawn()?; } Err(e) => { write!(io::stderr(), "{}", e)?; |