Skip to content

Commit

Permalink
feat(whkd): continue execution on hotkey conflicts
Browse files Browse the repository at this point in the history
This commit ensures that execution will continue if a key binding
conflict is encountered.

If a conflict is encountered, the key combination and the bound command
will be logged out, informing the user of a conflict and bubbling up the
underlying error, before continuing to try to enable the remaining key
bindings in the whkdrc file.

re #8
  • Loading branch information
LGUG2Z committed Mar 14, 2023
1 parent 5757a75 commit ddf7928
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 55 deletions.
114 changes: 62 additions & 52 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "whkd"
version = "0.1.1"
version = "0.1.2"
authors = ["Jade Iqbal <[email protected]>"]
description = "A simple hotkey daemon for Windows"
categories = ["hotkey-daemon", "windows"]
Expand Down
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,20 @@ impl HkmData {
pub fn register(&self, hkm: &mut HotkeyManager<()>) -> Result<()> {
let cmd = self.command.clone();

hkm.register(self.vkey, self.mod_keys.as_slice(), move || {
if let Err(error) = hkm.register(self.vkey, self.mod_keys.as_slice(), move || {
if let Some(session_stdin) = SESSION_STDIN.lock().as_mut() {
if matches!(WHKDRC.shell, Shell::Pwsh | Shell::Powershell) {
println!("{cmd}");
}

writeln!(session_stdin, "{cmd}").expect("failed to execute command");
}
})?;
}) {
eprintln!(
"Unable to bind '{:?} + {}' to '{}' (error: {error}), ignoring this binding and continuing...",
self.mod_keys, self.vkey, self.command
);
}

Ok(())
}
Expand Down

0 comments on commit ddf7928

Please sign in to comment.