From ff875f1d70b491cbaf8897132d893cdebbde688c Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Fri, 20 Jun 2025 05:36:11 +0200 Subject: [PATCH] :wrench: Add option to restart menu cycle when pressing the same shortcut again --- locales/en/translation.json | 5 +++-- src/common/index.ts | 2 +- src/main/menu-window.ts | 12 ++++++++++-- .../components/dialogs/GeneralSettingsDialog.tsx | 8 ++++++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/locales/en/translation.json b/locales/en/translation.json index 3061a6eb8..132e03f2e 100644 --- a/locales/en/translation.json +++ b/locales/en/translation.json @@ -27,12 +27,12 @@ }, "general-settings-dialog": { "none": "None", + "auto-language": "Use system language", "title": "General Settings", "message": "All settings of Kando are stored in a JSON file which you can also edit, share, or backup. Click [here]({{link}}) to open the directory where the config.json file is stored.", "app-settings": "Application Settings", "localization-label": "Language", "localization-info": "Restart Kando to apply the new language.", - "auto-language": "Use system language", "check-for-new-versions": "Check for new versions", "check-for-new-versions-info": "If enabled, Kando will show a notification when a new version is available.", "invisible-settings-button": "Invisible settings button", @@ -80,7 +80,8 @@ "press-again-behavior": "Press-shortcut-again behavior", "press-again-behavior-info": "This determines what happens when the shortcut is pressed again while a menu is shown. If multiple menus are assigned to the same shortcut, you can use this to cycle through all matching menus. Make sure to only hold down a modifier key if you want to use Turbo Mode together with an option other than 'Do nothing'.", "do-nothing": "Do nothing", - "cycle-menus": "Cycle through matching menus", + "cycle-from-first": "Show next menu (begin at first)", + "cycle-from-recent": "Show next menu (continue from last)", "close-menu": "Close menu", "menu-sounds": "Menu Sounds", "learn-how-to-add-sound-themes": "Learn how to add new sound themes to Kando [here]({{link}})!", diff --git a/src/common/index.ts b/src/common/index.ts index c231e54fa..f3d346ca1 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -649,7 +649,7 @@ export interface IGeneralSettings { gamepadCloseButton: number; /** Determines the behavior of pressing the trigger shortcut once the menu is open. */ - sameShortcutBehavior: 'cycle' | 'close' | 'nothing'; + sameShortcutBehavior: 'cycle-from-first' | 'cycle-from-recent' | 'close' | 'nothing'; /** * If enabled, pressing 'cmd + ,' on macOS or 'ctrl + ,' on Linux or Windows will open diff --git a/src/main/menu-window.ts b/src/main/menu-window.ts index 4d12a104a..bc8c63b55 100644 --- a/src/main/menu-window.ts +++ b/src/main/menu-window.ts @@ -144,10 +144,17 @@ export class MenuWindow extends BrowserWindow { // If the 'sameShortcutBehavior' is set to 'cycle', we will show the next menu which // matches the current request. - if (sameShortcutBehavior === 'cycle') { + if ( + sameShortcutBehavior === 'cycle-from-first' || + sameShortcutBehavior === 'cycle-from-recent' + ) { this.menuIndex += 1; } } + } else if (sameShortcutBehavior === 'cycle-from-first') { + // If the menu is not visible and the 'sameShortcutBehavior' is set to 'cycle-from-first', + // we reset the menu index to 0. This way, the first menu will be shown again. + this.menuIndex = 0; } // Select correct menu before showing it to user. @@ -485,7 +492,8 @@ export class MenuWindow extends BrowserWindow { // If the sameShortcutBehavior is set to 'cycle', we select the menu at the current // index. If the index is out of bounds, we wrap around to the first menu. - if (this.kando.getGeneralSettings().get('sameShortcutBehavior') === 'cycle') { + const behavior = this.kando.getGeneralSettings().get('sameShortcutBehavior'); + if (behavior === 'cycle-from-first' || behavior === 'cycle-from-recent') { return bestMenus[this.menuIndex % bestMenus.length]; } diff --git a/src/settings-renderer/components/dialogs/GeneralSettingsDialog.tsx b/src/settings-renderer/components/dialogs/GeneralSettingsDialog.tsx index a5d163886..d0d53c6da 100644 --- a/src/settings-renderer/components/dialogs/GeneralSettingsDialog.tsx +++ b/src/settings-renderer/components/dialogs/GeneralSettingsDialog.tsx @@ -296,8 +296,12 @@ export default function GeneralSettingsDialog() { label: i18next.t('settings.general-settings-dialog.do-nothing'), }, { - value: 'cycle', - label: i18next.t('settings.general-settings-dialog.cycle-menus'), + value: 'cycle-from-first', + label: i18next.t('settings.general-settings-dialog.cycle-from-first'), + }, + { + value: 'cycle-from-recent', + label: i18next.t('settings.general-settings-dialog.cycle-from-recent'), }, { value: 'close',