Skip to content

Commit

Permalink
ui.js: fix duplicate event on mouse click
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
throwaway96 committed Mar 29, 2024
1 parent e853522 commit cdc8ea6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cdc8ea6

Please sign in to comment.