fix(screen-mirror): grant display-capture permission in Electron executables#276
fix(screen-mirror): grant display-capture permission in Electron executables#276Muneerali199 wants to merge 10 commits into
Conversation
- Add GamepadUI component with virtual joysticks and buttons - Add useGamepad hook for touch/click handling with throttling - Update WebSocket server to handle gamepad messages - Update InputHandler to process gamepad inputs with deadzone - Add gamepad toggle to ControlBar Implements AOSSIE-Org#223
- Merge upstream/main (InputHandler try-catch hardening, websocket cleanup) - Remove server-side gamepad relay (aligns with upstream revert of that feature) - Remove useGamepad.ts hook (no longer needed; demo is client-side only) - Fix GamepadButton: tabIndex=-1, e.preventDefault() on all pointer events, touch-none to suppress mobile keyboard - Fix onBlur guard in trackpad.tsx to not re-focus hidden input when gamepad/demo is active - Fix toggleDemo to close keyboard on open - Add GamepadDemo: space-shooter canvas game showcasing all four buttons and joystick - Add Play button to ControlBar to launch demo mode
GamepadDemo.tsx:
- Convert game loop to delta-time (rAF timestamp + dt = min((ts-lastTs)/1000, 0.1))
- All speeds in units/sec, timers in seconds, particles use dt-scaled damping
- Bootstrap frame skips physics on first tick; dt capped at 100ms to survive tab resume
GamepadUI.tsx:
- Add pointer capture in Joystick: setPointerCapture on start, releasePointerCapture on end
so drags outside the element boundary still track correctly
- Add useEffect to reset state and emit zeroed snapshot when visible becomes false,
preventing stale button/stick state from persisting after overlay closes
ControlBar.tsx:
- Replace onPointerDown with onClick on Gamepad and Demo toggle buttons for keyboard accessibility
- Add aria-pressed={gamepadOpen} and aria-pressed={demoOpen} to expose toggle state to assistive tech
trackpad.tsx + useGamepad.ts + websocket.ts:
- Restore useGamepad hook (re-created from deleted file) with GamepadState import
from GamepadUI instead of the removed types.tsx definition
- Restore sendGamepadState call in handleGamepadStateChange so host receives controller input
- Re-add 'gamepad' to VALID_INPUT_TYPES whitelist in websocket.ts
InputHandler.ts:
- Fix held-stick bug: derive dx/dy from current deflection (currLeftX * SCALE)
instead of packet-to-packet delta so holding stick moves cursor continuously
- Add payload validation/normalisation in handleGamepad: clamp axis values to [-1,1],
coerce to Number with 0 fallback, guard buttons object, use safe ?. / ?? lookups
throughout to prevent NaN or throws from malformed packets
- GamepadUI: setPointerCapture on button onPointerDown + onLostPointerCapture handler; removes onPointerLeave so held touches are never cancelled by drag - useGamepad: replace drop-on-throttle with pendingState ref + delayed flush so the last state in every throttle window is always delivered - InputHandler: remove early return on null prev; use zeroed baseline instead so first-packet button presses are never dropped - InputHandler: replace single previousGamepadState field with per-socket Map to eliminate cross-client state leakage; add clearSocketState() method - websocket: pass ws socket to handleMessage; call clearSocketState on close - InputHandler: add LT/RT release-edge detection; key handler respects press=true/false for hold vs release vs tap semantics
|
Caution Review failedPull request was closed or merged during review WalkthroughThis PR adds gamepad/controller input support to the application, including new UI components for on-screen joystick and buttons, a game demo component, state management with debouncing, and server-side input handling with button mapping and deadzone normalization. Changes
Sequence DiagramsequenceDiagram
participant User
participant GamepadUI
participant useGamepad
participant WebSocket as WebSocket (Client)
participant WSServer as WebSocket (Server)
participant InputHandler
User->>GamepadUI: Interact (joystick/buttons)
GamepadUI->>GamepadUI: Update internal state
GamepadUI->>useGamepad: onStateChange(gamepadState)
useGamepad->>useGamepad: Diff & throttle check
alt Throttle window passed or forced flush
useGamepad->>WebSocket: Send gamepad message
else Within throttle window
useGamepad->>useGamepad: Queue as pending
useGamepad->>useGamepad: Schedule debounced flush
end
WebSocket->>WSServer: Transmit gamepad message
WSServer->>InputHandler: handleMessage(msg, ws)
InputHandler->>InputHandler: Apply deadzone normalization
InputHandler->>InputHandler: Detect button state changes
InputHandler->>InputHandler: Generate move/key events
Estimated code review effort🎯 4 (Complex) | ⏱️ ~70 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Changes
Testing
Summary by CodeRabbit
New Features
Chores