Skip to content

Commit

Permalink
Refactor Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
newtoallofthis123 committed Feb 28, 2024
1 parent 920bd79 commit e4084f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 2 additions & 11 deletions swhkd/src/daemon.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -71,7 +70,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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);
Expand Down Expand Up @@ -225,7 +224,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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() => {
Expand Down Expand Up @@ -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.");
Expand Down
8 changes: 8 additions & 0 deletions swhkd/src/environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit e4084f4

Please sign in to comment.