From bce6651fe44836a5f35ac0fcf06005167e6c58be Mon Sep 17 00:00:00 2001 From: Polochon_street Date: Thu, 8 Feb 2024 21:45:07 +0100 Subject: [PATCH] Fix compilation for non-linux OSes --- CHANGELOG.md | 3 +++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 23 ++++++++++++++--------- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6f0920..6f1c466 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## blissify 0.3.10 +* Fix compilation for non-linux OSes + ## blissify 0.3.9 * Add support for hostnames and abstract sockets in MPD_HOST diff --git a/Cargo.lock b/Cargo.lock index bebbd2e..507c907 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -148,7 +148,7 @@ dependencies = [ [[package]] name = "blissify" -version = "0.3.8" +version = "0.3.10" dependencies = [ "anyhow", "bliss-audio", diff --git a/Cargo.toml b/Cargo.toml index cf47745..746467f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blissify" -version = "0.3.9" +version = "0.3.10" authors = ["Polochon-street "] edition = "2021" license = "GPL-3.0-only" diff --git a/src/main.rs b/src/main.rs index f07238c..15e9807 100644 --- a/src/main.rs +++ b/src/main.rs @@ -131,6 +131,7 @@ impl MPDLibrary { /// variables. #[cfg(not(test))] fn get_mpd_conn() -> Result> { + #[cfg(target_os = "linux")] use std::os::linux::net::SocketAddrExt; use std::os::unix::net::SocketAddr; @@ -161,18 +162,22 @@ impl MPDLibrary { // find a solution that doesn't depend on a url crate that pulls the entire internet // with it if mpd_host.starts_with('/') || mpd_host.starts_with('~') { - Client::new(MPDStream::Unix(UnixStream::connect(mpd_host)?))? - } else if mpd_host.starts_with('@') { + return Ok(Client::new(MPDStream::Unix(UnixStream::connect( + mpd_host, + )?))?); + } + #[cfg(target_os = "linux")] + if mpd_host.starts_with('@') { let addr = SocketAddr::from_abstract_name(mpd_host.split_once('@').unwrap().1)?; - Client::new(MPDStream::Unix(UnixStream::connect_addr(&addr)?))? + return Ok(Client::new(MPDStream::Unix(UnixStream::connect_addr( + &addr, + )?))?); } // It is a hostname or an IP address - else { - Client::new(MPDStream::Tcp(TcpStream::connect(format!( - "{}:{}", - mpd_host, mpd_port - ))?))? - } + Client::new(MPDStream::Tcp(TcpStream::connect(format!( + "{}:{}", + mpd_host, mpd_port + ))?))? }; if let Some(pw) = password { client.login(&pw)?;