Repository: oliverschwendener/ueli (ts)

Issue:
[Bug] V9, Ctrl+Shift+F2 not possible hotkey
Bug similar to #1150 

Previously, control + shift + F2 was possible in V8, and with what is written in electron documentation, it should be possible to do it, is it possible to fix it ?

# Preview

![image](https://github.com/user-attachments/assets/8d434473-8eef-4626-8048-3244930dc747)


Pull request description:
fix(Hotkey): Support multiple modifiers
Fixes #1156 

Patch:
diff --git a/src/common/Core/Hotkey.ts b/src/common/Core/Hotkey.ts
index 6f32d933..22842584 100644
--- a/src/common/Core/Hotkey.ts
+++ b/src/common/Core/Hotkey.ts
@@ -18,6 +18,8 @@ const isValidKeyCode = (keyCode: string): boolean => {
 const isValidModifier = (modifier: string): boolean =>
     /^(Command|Cmd|Control|Ctrl|CommandOrControl|CmdOrCtrl|Alt|Option|AltGr|Shift|Super|Meta)$/.test(modifier);
 
+const hasDuplicates = (modifiers: string[]): boolean => modifiers.length !== new Set(modifiers).size;
+
 /**
  * Checks if the given string is a valid hotkey.
  * A valid hotkey is a combination of a modifier and a key code, e.g. `CmdOrCtrl+Space`. For more information, see
@@ -27,9 +29,12 @@ const isValidModifier = (modifier: string): boolean =>
  */
 export const isValidHotkey = (hotkey: string) => {
     const parts = hotkey.split("+");
-    const hasModifier = parts.length > 1;
-    const keyCode = hasModifier ? parts[1] : parts[0];
-    const modifier = hasModifier ? parts[0] : undefined;
+    const hasModifiers = parts.length > 1;
+    const keyCode = hasModifiers ? parts[parts.length - 1] : parts[0];
+    const modifiers = hasModifiers ? parts.slice(0, parts.length - 1) : undefined;
 
-    return isValidKeyCode(keyCode) && (modifier ? isValidModifier(modifier) : true);
+    return (
+        isValidKeyCode(keyCode) &&
+        (modifiers ? modifiers.every((modifier) => isValidModifier(modifier)) && !hasDuplicates(modifiers) : true)
+    );
 };


Test patch:
diff --git a/src/common/Core/Hotkey.test.ts b/src/common/Core/Hotkey.test.ts
index 672d69e4..fd4f31cc 100644
--- a/src/common/Core/Hotkey.test.ts
+++ b/src/common/Core/Hotkey.test.ts
@@ -30,12 +30,27 @@ describe(isValidHotkey, () => {
                 "Alt+]",
                 "Alt+(",
                 "Alt+)",
+                "Ctrl+Shift+Space",
+                "Alt+Shift+F2",
+                "Ctrl+Alt+Shift+Super+F8",
             ],
         }));
 
     it("should return false for all invalid hotkeys", () =>
         testIsValidHotkey({
             expected: false,
-            hotkeys: ["Space+Alt", "", " ", "abc", "F25", "Windows+Space", "Alt Space"],
+            hotkeys: [
+                "Space+Alt",
+                "",
+                " ",
+                "abc",
+                "F25",
+                "Windows+Space",
+                "Alt Space",
+                "Shift+Shift+Space",
+                "Ctrl+Space+F",
+                "Shift+Space+Ctrl",
+                "F+Shift",
+            ],
         }));
 });