Skip to content

Commit 7717d8a

Browse files
committed
add changes from pr #249 commit: bbc69a8e8a15276415d4b45ce66675929f898aa2
1 parent 6d1a115 commit 7717d8a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

swhkd/src/daemon.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
9595

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

98+
// If no config is present
99+
// Creates a default config at location (read man 5 swhkd)
100+
101+
if !Path::new(&config_file_path).exists() {
102+
log::warn!("No config found at path: {:#?}", config_file_path);
103+
create_default_config(invoking_uid, &config_file_path);
104+
}
105+
98106
match config::load(&config_file_path) {
99107
Err(e) => {
100108
log::error!("Config Error: {}", e);
@@ -494,6 +502,23 @@ pub fn setup_swhkd(invoking_uid: u32, runtime_path: String) {
494502
}
495503
}
496504

505+
pub fn create_default_config(invoking_uid: u32, config_file_path: &PathBuf) {
506+
// Initializes a default SWHKD config at specific config path
507+
508+
perms::raise_privileges();
509+
_ = match fs::File::create(&config_file_path) {
510+
Ok(mut file) => {
511+
log::debug!("Created default SWHKD config at: {:#?}", config_file_path);
512+
_ = 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");
513+
}
514+
Err(err) => {
515+
log::error!("Error creating config file: {}", err);
516+
exit(1);
517+
}
518+
};
519+
perms::drop_privileges(invoking_uid);
520+
}
521+
497522
pub fn send_command(
498523
hotkey: Hotkey,
499524
socket_path: &Path,

0 commit comments

Comments
 (0)