diff --git a/Cargo.toml b/Cargo.toml index b12bf1b..c8ee8b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ tokio-timer = "0.2" unicode-width = "0.1.5" dbus = { version = "0.6.4", optional = true } rand = "0.6.5" +webbrowser = "0.4" [dependencies.librespot] git = "https://github.com/librespot-org/librespot.git" diff --git a/src/authentication.rs b/src/authentication.rs index 5637287..308f51c 100644 --- a/src/authentication.rs +++ b/src/authentication.rs @@ -62,7 +62,8 @@ pub fn create_credentials(path: &Path) -> Result { let login_view = LinearLayout::new(cursive::direction::Orientation::Vertical) .child(url_notice) .child(controls); - url_open(urls.get("login_url").unwrap().to_string()); + let url = urls.get("login_url").unwrap(); + webbrowser::open(url).ok(); crappy_poller(urls.get("credentials_url").unwrap(), &s.cb_sink()); s.pop_layer(); s.add_layer(login_view) @@ -135,35 +136,3 @@ pub struct AuthResponse { pub credentials: RespotCredentials, pub error: Option, } - -// Thanks to Marko Mijalkovic for this, but I don't want the url crate - -#[cfg(target_os = "windows")] -pub fn url_open(url: String) { - extern crate shell32; - extern crate winapi; - - use std::ffi::CString; - use std::ptr; - - unsafe { - shell32::ShellExecuteA( - ptr::null_mut(), - CString::new("open").unwrap().as_ptr(), - CString::new(url.replace("\n", "%0A")).unwrap().as_ptr(), - ptr::null(), - ptr::null(), - winapi::SW_SHOWNORMAL, - ); - } -} - -#[cfg(target_os = "macos")] -pub fn url_open(url: String) { - let _ = std::process::Command::new("open").arg(url).output(); -} - -#[cfg(target_os = "linux")] -pub fn url_open(url: String) { - let _ = std::process::Command::new("xdg-open").arg(url).output(); -} diff --git a/src/main.rs b/src/main.rs index 2d898e1..d59c65b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ extern crate tokio; extern crate tokio_core; extern crate tokio_timer; extern crate unicode_width; +extern crate webbrowser; #[cfg(feature = "mpris")] extern crate dbus;