From 37dcacc7af0d489c3da2ddb46964e84a431f911f Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Mon, 26 Aug 2024 18:08:27 +0200 Subject: [PATCH] :bug: Fix unbinding of shortcuts --- src/main/app.ts | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/main/app.ts b/src/main/app.ts index 44839f2f..ef47ece3 100644 --- a/src/main/app.ts +++ b/src/main/app.ts @@ -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