Skip to content

Commit

Permalink
[fix] Apply env refactoring to swhkd
Browse files Browse the repository at this point in the history
Signed-off-by: innocentzero <[email protected]>
  • Loading branch information
InnocentZero committed Mar 26, 2024
1 parent 1e9a8a9 commit e7bb4c3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 91 deletions.
66 changes: 4 additions & 62 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 1 addition & 29 deletions swhkd/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
perms::drop_privileges(invoking_uid);

let config_file_path: PathBuf =
args.config.as_ref().map_or_else(fetch_xdg_config_path, |file| file.clone());
args.config.as_ref().map_or_else(|| env.fetch_xdg_config_path(), |file| file.clone());

log::debug!("Using config file path: {:#?}", config_file_path);

Expand Down Expand Up @@ -479,34 +479,6 @@ pub fn check_device_is_keyboard(device: &Device) -> bool {
}
}

pub fn fetch_xdg_config_path() -> PathBuf {
let config_file_path: PathBuf = match env::var("XDG_CONFIG_HOME") {
Ok(val) => {
log::debug!("XDG_CONFIG_HOME exists: {:#?}", val);
Path::new(&val).join("swhkd/swhkdrc")
}
Err(_) => {
log::error!("XDG_CONFIG_HOME has not been set.");
Path::new("/etc/swhkd/swhkdrc").to_path_buf()
}
};
config_file_path
}

pub fn fetch_xdg_runtime_socket_path() -> PathBuf {
match env::var("XDG_RUNTIME_DIR") {
Ok(val) => {
log::debug!("XDG_RUNTIME_DIR exists: {:#?}", val);
Path::new(&val).join("swhkd.sock")
}
Err(_) => {
log::error!("XDG_RUNTIME_DIR has not been set.");
Path::new(&format!("/run/user/{}/swhkd.sock", env::var("PKEXEC_UID").unwrap()))
.to_path_buf()
}
}
}

pub fn setup_swhkd(invoking_uid: u32, runtime_path: String) {
// Set a sane process umask.
log::trace!("Setting process umask.");
Expand Down

0 comments on commit e7bb4c3

Please sign in to comment.