From cdc8ea6e2e7ebad6efa64efc539f16a0cc909352 Mon Sep 17 00:00:00 2001 From: throwaway96 <68320646+throwaway96@users.noreply.github.com> Date: Thu, 28 Mar 2024 21:33:35 -0400 Subject: [PATCH] ui.js: fix duplicate event on mouse click On clicks, the YouTube app generates key events with keyCode 13 ("OK" button). We should not be sending our own click events for these, as they already exist. --- src/ui.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ui.js b/src/ui.js index 16dcf4cc..d02b61b3 100644 --- a/src/ui.js +++ b/src/ui.js @@ -83,8 +83,13 @@ function createOptionsPanel() { if (evt.keyCode in ARROW_KEY_CODE) { navigate(ARROW_KEY_CODE[evt.keyCode]); } else if (evt.keyCode === 13) { - // "OK" button - document.querySelector(':focus').click(); + // The YouTube app generates these "OK" events from clicks (including + // with the Magic Remote), and we don't want to send a duplicate click + // event for those. It seems isTrusted is only true for "real" events. + if (evt.isTrusted === true) { + // "OK" button + document.querySelector(':focus').click(); + } } else if (evt.keyCode === 27) { // Back button showOptionsPanel(false);