From 4007c40ba6c04d0a55edc5878c1c2b6d22177101 Mon Sep 17 00:00:00 2001 From: mars Date: Tue, 29 Nov 2022 18:01:09 -0700 Subject: [PATCH] Add find_socket() to Magpie --- apps/magpie/src/protocol.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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::*;