diff --git a/Cargo.toml b/Cargo.toml index 9e2d3ce..ee21577 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ futures-lite = { version = "1.13.0" } async-process = { version = "1.7.0" } itertools = { version = "0.11.0" } x11rb = { version = "0.12.0", default-features = false, features = ["composite"], optional = true } +shellexpand = "3.1.0" [features] default = ["egl", "winit", "udev", "xwayland"] diff --git a/src/api.rs b/src/api.rs index 2653973..b13e4fb 100644 --- a/src/api.rs +++ b/src/api.rs @@ -97,20 +97,30 @@ impl PinnacleSocketSource { )); } - let socket_path = socket_path.join("pinnacle_socket"); + let Some(socket_path) = socket_path + .join("pinnacle_socket") + .to_str() + .map(|st| st.to_string()) + else { + tracing::error!("Socket path {socket_path:?} had invalid Unicode"); + return Err(io::Error::new(io::ErrorKind::Other, "socket path had invalid unicode")); + }; + + let socket_path = shellexpand::tilde(&socket_path).to_string(); + let socket_path = Path::new(&socket_path); // TODO: use anyhow if let Ok(exists) = socket_path.try_exists() { if exists { - if let Err(err) = std::fs::remove_file(&socket_path) { + if let Err(err) = std::fs::remove_file(socket_path) { tracing::error!("Failed to remove old socket: {err}"); return Err(err); } } } - let listener = match UnixListener::bind(&socket_path) { + let listener = match UnixListener::bind(socket_path) { Ok(listener) => { tracing::info!("Bound to socket at {socket_path:?}"); listener