Skip to content

Commit

Permalink
🐛 Fix unbinding of shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
Schneegans committed Aug 26, 2024
1 parent d78d322 commit 37dcacc
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,28 +360,32 @@ export class KandoApp {
// shortcut for the previous menu had been unbound when showing it, we have to
// rebind it here (if it was a different one).
const useID = !this.backend.getBackendInfo().supportsShortcuts;
const newTrigger = useID ? menu.shortcut : menu.shortcutID;
const oldTrigger = useID ? this.lastMenu?.shortcut : this.lastMenu?.shortcutID;

if (this.window.isVisible() && oldTrigger != newTrigger) {
// Rebind the trigger for the previous menu. If the hideTimeout is set, the
// window is about to be hidden and the shortcuts have been rebound already.
if (oldTrigger && !this.hideTimeout) {
this.backend.bindShortcut({
trigger: oldTrigger,
action: () => {
this.showMenu({
trigger: oldTrigger,
name: '',
});
},
});
}
const newTrigger = useID ? menu.shortcutID : menu.shortcut;
const oldTrigger = useID ? this.lastMenu?.shortcutID : this.lastMenu?.shortcut;

// Unbind the trigger for the new menu.
if (newTrigger) {
this.backend.unbindShortcut(newTrigger);
}
// First, unbind the trigger for the new menu.
if (newTrigger) {
this.backend.unbindShortcut(newTrigger);
}

// If old and new trigger are the same, we don't need to rebind it. If the
// hideTimeout is set, the window is about to be hidden and the shortcuts have
// been rebound already.
if (
oldTrigger &&
oldTrigger != newTrigger &&
this.window.isVisible() &&
!this.hideTimeout
) {
this.backend.bindShortcut({
trigger: oldTrigger,
action: () => {
this.showMenu({
trigger: oldTrigger,
name: '',
});
},
});
}

// Store the last menu to be able to execute the selected action later. The WMInfo
Expand Down

0 comments on commit 37dcacc

Please sign in to comment.