From e4084f4966379819e6ee9dadce2fd3af1cfbba21 Mon Sep 17 00:00:00 2001 From: newtoallofthis123 Date: Wed, 28 Feb 2024 16:14:54 +0530 Subject: [PATCH] Refactor Functions --- swhkd/src/daemon.rs | 13 ++----------- swhkd/src/environ.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/swhkd/src/daemon.rs b/swhkd/src/daemon.rs index f162862..d8aa662 100644 --- a/swhkd/src/daemon.rs +++ b/swhkd/src/daemon.rs @@ -1,6 +1,5 @@ use crate::config::Value; use clap::{arg, Command}; -use environ::Env; use evdev::{AttributeSet, Device, InputEventKind, Key}; use nix::{ sys::stat::{umask, Mode}, @@ -71,7 +70,7 @@ async fn main() -> Result<(), Box> { let config_file_path: PathBuf = if args.is_present("config") { Path::new(args.value_of("config").unwrap()).to_path_buf() } else { - fetch_xdg_config_path(&env) + env.fetch_xdg_config_path() }; log::debug!("Using config file path: {:#?}", config_file_path); @@ -225,7 +224,7 @@ async fn main() -> Result<(), Box> { tokio::pin!(hotkey_repeat_timer); // The socket we're sending the commands to. - let socket_file_path = fetch_xdg_runtime_socket_path(&env); + let socket_file_path = env.fetch_xdg_runtime_socket_path(); loop { select! { _ = &mut hotkey_repeat_timer, if &last_hotkey.is_some() => { @@ -495,14 +494,6 @@ pub fn set_command_line_args() -> Command<'static> { app } -pub fn fetch_xdg_config_path(env: &Env) -> PathBuf { - PathBuf::from(&env.xdg_config_home).join("swhkd/swhkdrc") -} - -pub fn fetch_xdg_runtime_socket_path(env: &Env) -> PathBuf { - PathBuf::from(&env.xdg_runtime_dir).join("swhkd.sock") -} - pub fn setup_swhkd(invoking_uid: u32, runtime_path: String) { // Set a sane process umask. log::trace!("Setting process umask."); diff --git a/swhkd/src/environ.rs b/swhkd/src/environ.rs index 35227e2..9e9f552 100644 --- a/swhkd/src/environ.rs +++ b/swhkd/src/environ.rs @@ -94,4 +94,12 @@ impl Env { }, } } + + pub fn fetch_xdg_config_path(&self) -> PathBuf { + PathBuf::from(&self.xdg_config_home).join("swhkd/swhkdrc") + } + + pub fn fetch_xdg_runtime_socket_path(&self) -> PathBuf { + PathBuf::from(&self.xdg_runtime_dir).join("swhkd.sock") + } }