From df59b74cedf6db12419de43f3b45c71cf457896e Mon Sep 17 00:00:00 2001 From: missionfloyd Date: Sun, 28 May 2023 20:42:47 -0600 Subject: [PATCH 1/3] Only poll gamepads while connected --- javascript/imageviewerGamepad.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/javascript/imageviewerGamepad.js b/javascript/imageviewerGamepad.js index 31d226de..0510c02a 100644 --- a/javascript/imageviewerGamepad.js +++ b/javascript/imageviewerGamepad.js @@ -1,7 +1,9 @@ +let gamepads = []; + window.addEventListener('gamepadconnected', (e) => { const index = e.gamepad.index; let isWaiting = false; - setInterval(async() => { + gamepads[index] = setInterval(async() => { if (!opts.js_modal_lightbox_gamepad || isWaiting) return; const gamepad = navigator.getGamepads()[index]; const xValue = gamepad.axes[0]; @@ -22,6 +24,7 @@ window.addEventListener('gamepadconnected', (e) => { isWaiting = false; } }, 10); + window.addEventListener('gamepaddisconnected', (e) => clearInterval(gamepads[e.gamepad.index])) }); /* From 679e8738759b9aa2678a40d518bf6d67915e98fe Mon Sep 17 00:00:00 2001 From: missionfloyd Date: Sun, 28 May 2023 20:49:46 -0600 Subject: [PATCH 2/3] Update imageviewerGamepad.js --- javascript/imageviewerGamepad.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/imageviewerGamepad.js b/javascript/imageviewerGamepad.js index 0510c02a..45cc4cbf 100644 --- a/javascript/imageviewerGamepad.js +++ b/javascript/imageviewerGamepad.js @@ -24,7 +24,7 @@ window.addEventListener('gamepadconnected', (e) => { isWaiting = false; } }, 10); - window.addEventListener('gamepaddisconnected', (e) => clearInterval(gamepads[e.gamepad.index])) + window.addEventListener('gamepaddisconnected', (e) => clearInterval(gamepads[e.gamepad.index])); }); /* From baa81126c485434211cb6d58292f77de00dc2432 Mon Sep 17 00:00:00 2001 From: missionfloyd Date: Mon, 29 May 2023 23:52:19 -0600 Subject: [PATCH 3/3] Move gamepaddisconnected listener --- javascript/imageviewerGamepad.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/javascript/imageviewerGamepad.js b/javascript/imageviewerGamepad.js index 45cc4cbf..a22c7e6e 100644 --- a/javascript/imageviewerGamepad.js +++ b/javascript/imageviewerGamepad.js @@ -24,7 +24,10 @@ window.addEventListener('gamepadconnected', (e) => { isWaiting = false; } }, 10); - window.addEventListener('gamepaddisconnected', (e) => clearInterval(gamepads[e.gamepad.index])); +}); + +window.addEventListener('gamepaddisconnected', (e) => { + clearInterval(gamepads[e.gamepad.index]); }); /*