Skip to content

fix(flatpak): add Flatpak distribution support - #277

Closed
Muneerali199 wants to merge 10 commits into
AOSSIE-Org:mainfrom
Muneerali199:fix/flatpak-v2
Closed

Muneerali199 wants to merge 10 commits into
AOSSIE-Org:mainfrom
Muneerali199:fix/flatpak-v2

Conversation

@Muneerali199

@Muneerali199 Muneerali199 commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add Flatpak CI workflow (.github/workflows/flatpak.yml) for building Flatpak bundles
  • Add Flatpak manifest (flatpak/com.rein.app.yml) with Electron runtime configuration
  • Add .desktop file for Linux desktop integration
  • Add AppStream metainfo for software center discoverability
  • Add linux target to package.json for electron-builder

Changes

  • .github/workflows/flatpak.yml: CI pipeline for Flatpak distribution
  • flatpak/com.rein.app.yml: Flatpak manifest with Wayland/X11 support
  • flatpak/com.rein.app.desktop: Desktop entry file
  • flatpak/com.rein.app.metainfo.xml: AppStream metadata
  • package.json: Added linux build target

Testing

  • Verify CI pipeline runs successfully
  • Test Flatpak bundle installation on Linux

Summary by CodeRabbit

Release Notes

  • New Features
    • Added virtual gamepad controller with on-screen joystick and action buttons for interactive input
    • Added interactive game demo powered by gamepad controls
    • Added Flatpak support for Linux distribution and packaging
    • Added Linux-specific build configuration for desktop applications

- 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
@coderabbitai

coderabbitai Bot commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

This PR adds comprehensive Flatpak packaging infrastructure for distributing the Electron application on Linux, alongside a new gamepad input system enabling wireless controller support. The changes span CI/CD workflows, desktop packaging metadata, client-side gamepad UI components, input state management through a custom hook, and server-side gamepad event handling.

Changes

Cohort / File(s) Summary
Flatpak Packaging
.github/workflows/flatpak.yml, flatpak/com.rein.app.desktop, flatpak/com.rein.app.metainfo.xml, flatpak/com.rein.app.yml, package.json
Introduces complete Flatpak build and distribution setup: GitHub Actions workflow to build and package the app, desktop entry file for launcher configuration, AppStream metadata with release notes and content ratings, comprehensive Flatpak manifest with runtime/SDK/extension definitions and offline npm build steps, and Linux-specific Electron Builder target configuration.
Gamepad UI Components
src/components/Gamepad/GamepadUI.tsx, src/components/Gamepad/GamepadDemo.tsx, src/components/Trackpad/ControlBar.tsx
Adds interactive virtual gamepad (Joystick and ABXY buttons), full arcade-style game demo component with collision detection and game mechanics, and extends ControlBar with gamepad and demo toggle buttons.
Gamepad Input Integration
src/hooks/useGamepad.ts, src/routes/trackpad.tsx, src/server/InputHandler.ts, src/server/websocket.ts
Implements gamepad state synchronization: custom hook with throttling and diff-based change detection, route-level state management and UI composition, server-side gamepad message handling with axis normalization and button-to-key translation, and WebSocket cleanup for per-connection state.
Type Definitions & Config
src/types.tsx, biome.json
Adds public GamepadState, GamepadMessage interfaces and expands InputMessageType union; excludes generated sources from linting.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant GamepadUI as Gamepad UI
    participant useGamepad as useGamepad Hook
    participant WebSocket as WebSocket
    participant InputHandler as InputHandler
    participant DesktopEnv as Desktop Environment

    User->>GamepadUI: Move joystick / Press button
    GamepadUI->>GamepadUI: Update local state
    GamepadUI->>useGamepad: Call onStateChange
    useGamepad->>useGamepad: Detect changes (diff-check)
    useGamepad->>useGamepad: Apply throttling (16ms)
    useGamepad->>WebSocket: Send gamepad message
    WebSocket->>InputHandler: Forward message with socket
    InputHandler->>InputHandler: Normalize axes & deadzone
    InputHandler->>InputHandler: Detect state transitions
    InputHandler->>DesktopEnv: Generate move/key events
    DesktopEnv->>User: Apply cursor/key input
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

Typescript Lang

Poem

🐰 A gamepad hops into view, buttons bright and bold,
Flatpak bundles the app so Linux tales can be told,
Joysticks dance while pixels fly, arcade dreams take flight,
From client to server, state flows true through the night! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provides a clear summary and lists specific changes, but is largely incomplete against the template—missing addressed issues link, screenshots, functional verification checklist, and additional context. Link an issue with 'Fixes #(issue number)', add screenshots if applicable, complete the Functional Verification checklist, and fill out the Additional Notes and Checklist sections per template requirements.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(flatpak): add Flatpak distribution support' directly and clearly describes the main change—adding Flatpak distribution support across multiple files and configurations.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Muneerali199
Muneerali199 deleted the fix/flatpak-v2 branch March 9, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant