fix(skin): match macOS recovery shortcut by physical key code and forbid toolbar hook attribute

This commit is contained in:
OddTurtleHead committed 2026-11-26 23:06:43 +08:00
1 parent 881354e283
commit cfbf488f75
7 files changed
+63 -6

No files matched your search

+28
View File
@@ -217,6 +217,32 @@ try {
toolbarOpen: isOpen(toolbar()),
};
// On macOS ⌥/⇧ turn the letter into a derived character (US layout: ®), so
// `key` is not "r". The physical code must match. A skin-style capture
// listener calling preventDefault() must not swallow the chord either.
const skinCapture = (event) => { if (event.type === "keydown") event.preventDefault(); };
window.addEventListener("keydown", skinCapture, true);
window.dispatchEvent(new KeyboardEvent("keydown", {
key: "®", code: "KeyR", metaKey: true, altKey: true, shiftKey: true, bubbles: true, cancelable: true,
}));
window.removeEventListener("keydown", skinCapture, true);
await nextTick();
await sleep(80);
const macShortcut = {
capsuleOpen: isOpen(capsule()),
toolbarOpen: isOpen(toolbar()),
focusedAction: layer.shadow.activeElement?.getAttribute?.("data-ws-recovery-action") ?? null,
capsuleActions: [...(capsule()?.querySelectorAll("[data-ws-recovery-action]") ?? [])]
.map((button) => button.getAttribute("data-ws-recovery-action")),
};
capsule().dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
await nextTick();
await sleep(150);
const afterMacEscape = {
capsuleOpen: isOpen(capsule()),
toolbarOpen: isOpen(toolbar()),
};
// Invalid / unreadable toolbar tokens must not make the button invisible.
const voiceAnchor = document.getElementById("voice-anchor");
voiceAnchor.style.setProperty("--skin-recovery-toolbar-background", "rgba(0,0,0,0)");
@@ -242,6 +268,8 @@ try {
redocked,
shortcut,
afterEscape,
macShortcut,
afterMacEscape,
invalidTokens,
});
} catch (error) {
+9
View File
@@ -593,6 +593,15 @@ test("toolbar-mode recovery docks plain host buttons, de-duplicates the library
assert.equal(payload.afterEscape.capsuleOpen, false);
assert.equal(payload.afterEscape.toolbarOpen, true, "closing the shortcut did not restore the docked toolbar");
// The macOS chord arrives with a derived `key` (®) + physical `code` KeyR,
// under a capture listener that calls preventDefault(); it must still work.
assert.equal(payload.macShortcut.capsuleOpen, true, "the macOS ⌘⌥⇧R chord did not summon the capsule");
assert.equal(payload.macShortcut.toolbarOpen, false, "the macOS chord must yield to the summoned capsule");
assert.equal(payload.macShortcut.focusedAction, "built-in", "the macOS chord did not focus the first host button");
assert.deepEqual(payload.macShortcut.capsuleActions, ["built-in", "library"]);
assert.equal(payload.afterMacEscape.capsuleOpen, false);
assert.equal(payload.afterMacEscape.toolbarOpen, true, "closing the macOS chord did not restore the docked toolbar");
assert.equal(payload.invalidTokens.visible, true, "invalid toolbar tokens hid the button");
assert.equal(payload.invalidTokens.inViewport, true);
assert.equal(payload.invalidTokens.background, "rgb(255, 255, 255)", "transparent background must fall back to a visible surface");