diff options
author | Teddy Wing | 2017-05-09 00:27:05 +0200 |
---|---|---|
committer | Teddy Wing | 2017-05-09 00:27:05 +0200 |
commit | 6b40ada57809faa3494387173490afc48c3744a4 (patch) | |
tree | 5a5874e0aa3bc8c80d4c2fd63746504e8a4f1bb4 /src/main.rs | |
parent | 642102ddba1b3d39f4c0ca78c408d07657a11d56 (diff) | |
parent | 07ef413cff05a8a692288d6226aefc7f5a81d374 (diff) | |
download | HearURL-6b40ada57809faa3494387173490afc48c3744a4.tar.bz2 |
Merge branch 'parse-url'
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 60780fc..7956797 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,11 @@ extern crate getopts; +extern crate url; use getopts::Options; +use url::Url; use std::env; +use std::error::Error; use std::io::{self, Write}; use std::io::prelude::*; use std::net::TcpListener; @@ -10,7 +13,7 @@ use std::process::Command; const DEFAULT_PORT: u16 = 37705; -fn open_stream(browser: String, port: u16) -> io::Result<()> { +fn open_stream(browser: String, port: u16) -> Result<(), Box<Error>> { let listener = TcpListener::bind( format!("127.0.0.1:{}", port) )?; @@ -21,13 +24,12 @@ fn open_stream(browser: String, port: u16) -> io::Result<()> { let mut url = String::new(); stream.read_to_string(&mut url)?; + let url = Url::parse(url.as_str())?; + Command::new("open") .arg("-a") .arg(&browser) - - // Trim the trailing newline, otherwise this doesn't - // work - .arg(&url.trim_right()) + .arg(&url.as_str()) .spawn()?; } Err(e) => { |