Bladeren bron

Only poll gamepads while connected

missionfloyd 2 jaren geleden
bovenliggende
commit
df59b74ced
1 gewijzigde bestanden met toevoegingen van 4 en 1 verwijderingen
  1. 4 1
      javascript/imageviewerGamepad.js

+ 4 - 1
javascript/imageviewerGamepad.js

@@ -1,7 +1,9 @@
+let gamepads = [];
+
 window.addEventListener('gamepadconnected', (e) => {
 window.addEventListener('gamepadconnected', (e) => {
     const index = e.gamepad.index;
     const index = e.gamepad.index;
     let isWaiting = false;
     let isWaiting = false;
-    setInterval(async() => {
+    gamepads[index] = setInterval(async() => {
         if (!opts.js_modal_lightbox_gamepad || isWaiting) return;
         if (!opts.js_modal_lightbox_gamepad || isWaiting) return;
         const gamepad = navigator.getGamepads()[index];
         const gamepad = navigator.getGamepads()[index];
         const xValue = gamepad.axes[0];
         const xValue = gamepad.axes[0];
@@ -22,6 +24,7 @@ window.addEventListener('gamepadconnected', (e) => {
             isWaiting = false;
             isWaiting = false;
         }
         }
     }, 10);
     }, 10);
+    window.addEventListener('gamepaddisconnected', (e) => clearInterval(gamepads[e.gamepad.index]))
 });
 });
 
 
 /*
 /*