From 01e2aee16455fba8122b674a4753ef16a73076da Mon Sep 17 00:00:00 2001 From: Iris Pupo Date: Sun, 4 Dec 2022 00:03:55 -0500 Subject: [PATCH] added new function for listener struct --- apps/magpie/src/service/ipc.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/apps/magpie/src/service/ipc.rs b/apps/magpie/src/service/ipc.rs index c4271bf..1ecb694 100644 --- a/apps/magpie/src/service/ipc.rs +++ b/apps/magpie/src/service/ipc.rs @@ -66,6 +66,21 @@ impl DerefMut for Listener { } } +impl Listener { + fn new() -> std::io::Result{ + 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(SOCK_NAME); + eprintln!("Making socket at: {:?}", sock_path); + + let uds = UnixListener::bind(&sock_path)?; + let path = sock_path.to_path_buf(); + Ok(Self{uds, path}) + } + +} + + pub struct IpcData { poll: Poll, window_to_client_panel: HashMap, @@ -162,15 +177,8 @@ pub struct Ipc { impl Ipc { pub fn new(window_sender: WindowMessageSender) -> std::io::Result<(Self, IpcMessageSender)> { - 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(SOCK_NAME); - eprintln!("Making socket at: {:?}", sock_path); - let mut listener = Listener { - uds: UnixListener::bind(&sock_path)?, - path: sock_path.to_path_buf(), - }; + let mut listener = Listener::new()?; let mut signals = Signals::new(Signal::Interrupt | Signal::Quit)?; @@ -301,3 +309,4 @@ impl Ipc { } } } +