use webbrowser crate which is already a dependency in rspotify

This commit is contained in:
Henrik Friedrichsen
2019-03-30 22:36:05 +01:00
parent d78e71871a
commit d500466e2e
3 changed files with 4 additions and 33 deletions

View File

@@ -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"

View File

@@ -62,7 +62,8 @@ pub fn create_credentials(path: &Path) -> Result<RespotCredentials, String> {
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<String>,
}
// 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();
}

View File

@@ -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;