diff --git a/src/main/input/gamepadReader.ts b/src/main/input/gamepadReader.ts index f992687..80dd795 100644 --- a/src/main/input/gamepadReader.ts +++ b/src/main/input/gamepadReader.ts @@ -36,6 +36,9 @@ const REPEAT_INTERVAL_MS = 150 // L2/R2 Trigger: kein Auto-Repeat, da 300s-Spruenge nicht wiederholt werden sollen. const NO_REPEAT_AXES = new Set([2, 5]) const SCAN_INTERVAL_MS = 3000 +// Bluetooth-/Steam-Setups liefern dieselbe Eingabe teils über mehrere js*-Devices. +// Nahezu zeitgleiche identische Events werden deshalb global entdoppelt. +const DUPLICATE_EVENT_WINDOW_MS = 40 interface AxisState { key: string | null @@ -177,8 +180,14 @@ export function startGamepadReader(getWindow: () => BrowserWindow | null): () => if (process.platform !== 'linux') return () => {} const readers = new Map() + const lastKeyAt = new Map() const onKey = (key: string): void => { + const now = Date.now() + const lastAt = lastKeyAt.get(key) ?? 0 + if (now - lastAt < DUPLICATE_EVENT_WINDOW_MS) return + lastKeyAt.set(key, now) + const win = getWindow() if (!win || win.isDestroyed()) return win.webContents.send('gamepad-input', key) diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 3b3ce2f..1acf4d9 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -22,6 +22,7 @@ export default function App(): JSX.Element { // Browser Gamepad API (funktioniert im Desktop-Modus / Windows) useEffect(() => { + if (navigator.userAgent.toLowerCase().includes('linux')) return gamepadService.start() return () => gamepadService.stop() }, [])