mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
fix(skin): match macOS recovery shortcut by physical key code and forbid toolbar hook attribute
This commit is contained in:
1 parent
881354e283
commit
cfbf488f75
7 files changed
+63
-6
No files matched your search
@@ -133,16 +133,18 @@ export function requestBuiltInSkin(): void {
|
||||
builtInSkinRequests.value += 1;
|
||||
}
|
||||
|
||||
type RecoveryShortcutEvent = Pick<KeyboardEvent, "ctrlKey" | "metaKey" | "altKey" | "shiftKey" | "key">;
|
||||
type RecoveryShortcutEvent = Pick<KeyboardEvent, "ctrlKey" | "metaKey" | "altKey" | "shiftKey" | "key" | "code">;
|
||||
|
||||
/**
|
||||
* The documented recovery shortcut: Ctrl+Alt+Shift+R, or ⌘+⌥+⇧+R on macOS.
|
||||
* The letter is matched case-insensitively, but every modifier is required so
|
||||
* ordinary app shortcuts (Ctrl+R, Alt+R, Ctrl+Shift+R) keep their meaning.
|
||||
* On macOS, Option/Shift turn the letter key into a derived character (US
|
||||
* layout: ®), so `event.key` is not "r". Match the physical `code` as well;
|
||||
* every modifier is still required so ordinary app shortcuts (Ctrl+R, Alt+R,
|
||||
* Ctrl+Shift+R) keep their meaning.
|
||||
*/
|
||||
export function isRecoveryShortcut(event: RecoveryShortcutEvent): boolean {
|
||||
return (event.ctrlKey || event.metaKey)
|
||||
&& event.altKey
|
||||
&& event.shiftKey
|
||||
&& event.key.toLowerCase() === "r";
|
||||
&& (event.key?.toLowerCase() === "r" || event.code === "KeyR");
|
||||
}
|
||||
@@ -9,6 +9,7 @@ type ShortcutEvent = {
|
||||
altKey: boolean;
|
||||
shiftKey: boolean;
|
||||
key: string;
|
||||
code: string;
|
||||
};
|
||||
|
||||
const shortcut = (overrides: Partial<ShortcutEvent> = {}): ShortcutEvent => ({
|
||||
@@ -17,6 +18,7 @@ const shortcut = (overrides: Partial<ShortcutEvent> = {}): ShortcutEvent => ({
|
||||
altKey: false,
|
||||
shiftKey: false,
|
||||
key: "",
|
||||
code: "",
|
||||
...overrides,
|
||||
});
|
||||
|
||||
@@ -24,16 +26,28 @@ test("the recovery shortcut requires the full Ctrl/Cmd+Alt+Shift+R chord", () =>
|
||||
assert.equal(isRecoveryShortcut(shortcut({ ctrlKey: true, altKey: true, shiftKey: true, key: "r" })), true);
|
||||
// macOS uses the Meta/Command key in place of Ctrl.
|
||||
assert.equal(isRecoveryShortcut(shortcut({ metaKey: true, altKey: true, shiftKey: true, key: "R" })), true);
|
||||
// Option/Shift turn the letter into a derived character (US layout: ®) on
|
||||
// macOS; the physical key code must still match.
|
||||
assert.equal(isRecoveryShortcut(shortcut({
|
||||
metaKey: true, altKey: true, shiftKey: true, key: "®", code: "KeyR",
|
||||
})), true);
|
||||
assert.equal(isRecoveryShortcut(shortcut({
|
||||
ctrlKey: true, altKey: true, shiftKey: true, key: "®", code: "KeyR",
|
||||
})), true);
|
||||
|
||||
for (const rejected of [
|
||||
shortcut({ ctrlKey: true, altKey: true, shiftKey: true, key: "x" }),
|
||||
shortcut({ ctrlKey: true, altKey: true, shiftKey: true, key: "Enter" }),
|
||||
// A derived character alone is not enough: the physical key must be R.
|
||||
shortcut({ metaKey: true, altKey: true, shiftKey: true, key: "®", code: "KeyX" }),
|
||||
// Ordinary app/browser shortcuts must stay available.
|
||||
shortcut({ ctrlKey: true, key: "r" }),
|
||||
shortcut({ altKey: true, key: "r" }),
|
||||
shortcut({ ctrlKey: true, shiftKey: true, key: "r" }),
|
||||
shortcut({ ctrlKey: true, altKey: true, key: "r" }),
|
||||
shortcut({ ctrlKey: false, altKey: true, shiftKey: true, key: "r" }),
|
||||
// Incomplete modifiers stay rejected even when the physical code matches.
|
||||
shortcut({ ctrlKey: true, altKey: true, key: "®", code: "KeyR" }),
|
||||
]) {
|
||||
assert.equal(isRecoveryShortcut(rejected), false, JSON.stringify(rejected));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user