aboutsummaryrefslogtreecommitdiff
path: root/javascript
diff options
context:
space:
mode:
authormissionfloyd <missionfloyd@users.noreply.github.com>2023-05-28 20:42:47 -0600
committermissionfloyd <missionfloyd@users.noreply.github.com>2023-05-28 20:42:47 -0600
commitdf59b74cedf6db12419de43f3b45c71cf457896e (patch)
tree65e7bacd9c77994f525d7ad31f3deb3343177e33 /javascript
parent20ae71faa8ef035c31aa3a410b707d792c8203a3 (diff)
Only poll gamepads while connected
Diffstat (limited to 'javascript')
-rw-r--r--javascript/imageviewerGamepad.js5
1 files changed, 4 insertions, 1 deletions
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]))
});
/*