Skip to content

Commit

Permalink
add changes from pr waycrate#249 commit: bbc69a8
Browse files Browse the repository at this point in the history
  • Loading branch information
id3v1669 committed Jul 6, 2024
1 parent 6d1a115 commit 7717d8a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions swhkd/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ async fn main() -> Result<(), Box<dyn Error>> {

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

// If no config is present
// Creates a default config at location (read man 5 swhkd)

if !Path::new(&config_file_path).exists() {
log::warn!("No config found at path: {:#?}", config_file_path);
create_default_config(invoking_uid, &config_file_path);
}

match config::load(&config_file_path) {
Err(e) => {
log::error!("Config Error: {}", e);
Expand Down Expand Up @@ -494,6 +502,23 @@ pub fn setup_swhkd(invoking_uid: u32, runtime_path: String) {
}
}

pub fn create_default_config(invoking_uid: u32, config_file_path: &PathBuf) {
// Initializes a default SWHKD config at specific config path

perms::raise_privileges();
_ = match fs::File::create(&config_file_path) {
Ok(mut file) => {
log::debug!("Created default SWHKD config at: {:#?}", config_file_path);
_ = file.write_all(b"# Comments start with #, uncomment to use \n#start a terminal\n#super + return\n#\talacritty # replace with terminal of your choice");
}
Err(err) => {
log::error!("Error creating config file: {}", err);
exit(1);
}
};
perms::drop_privileges(invoking_uid);
}

pub fn send_command(
hotkey: Hotkey,
socket_path: &Path,
Expand Down

0 comments on commit 7717d8a

Please sign in to comment.