diff --git a/apps/magpie/src/protocol.rs b/apps/magpie/src/protocol.rs index eacf451..a8a016a 100644 --- a/apps/magpie/src/protocol.rs +++ b/apps/magpie/src/protocol.rs @@ -4,7 +4,7 @@ use std::collections::VecDeque; use std::io::{Read, Write}; use std::marker::PhantomData; -use std::path::PathBuf; +use std::path::{PathBuf, Path}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; @@ -211,6 +211,16 @@ impl Messenger { } } +/// Acquires the path to the Magpie socket. +/// +/// Currently only joins XDG_RUNTIME_DIR with [MAGPIE_SOCK]. +pub fn find_socket() -> PathBuf { + let sock_dir = std::env::var("XDG_RUNTIME_DIR").expect("XDG_RUNTIME_DIR not set"); + let sock_dir = Path::new(&sock_dir); + let sock_path = sock_dir.join(MAGPIE_SOCK); + sock_path +} + #[cfg(feature = "async")] mod async_messages { use super::*;