Skip to content

fix(screen-mirror): grant display-capture permission + Flatpak pipeline - #266

Closed
Muneerali199 wants to merge 4 commits into
AOSSIE-Org:mainfrom
Muneerali199:fix/screen-mirror-and-flatpak-pipeline
Closed

fix(screen-mirror): grant display-capture permission + Flatpak pipeline#266
Muneerali199 wants to merge 4 commits into
AOSSIE-Org:mainfrom
Muneerali199:fix/screen-mirror-and-flatpak-pipeline

Conversation

@Muneerali199

@Muneerali199 Muneerali199 commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix screen mirroring in packaged Electron executables by explicitly allowing display-capture/media permissions in the main process session handlers.
  • Add macOS startup checks for screen access status and keep app activation behavior consistent.
  • Add Flatpak packaging foundation: Linux dir target in electron-builder config, Flatpak manifest + desktop/metainfo files, and a GitHub Actions Flatpak workflow.

Why

Changes

  • electron/main.cjs
    • add setPermissionRequestHandler and setPermissionCheckHandler
    • set secure webPreferences
    • add macOS-specific startup handling and activate flow
  • package.json
    • add Linux build target (dir) for electron-builder
  • flatpak/com.rein.app.yml
  • flatpak/com.rein.app.desktop
  • flatpak/com.rein.app.metainfo.xml
  • .github/workflows/flatpak.yml

Notes

  • Flatpak npm offline source generation is wired in CI; local full build still requires generating flatpak/generated-sources.json when running manually.

Closes #254
Related to #206

Summary by CodeRabbit

  • New Features

    • Added cross-platform virtual input control for Windows, Linux, and macOS using native OS APIs
    • Introduced Flatpak packaging support for improved distribution
    • Added permission handling for media and screen access
  • Chores

    • Enhanced application security with context isolation
    • Added automated build workflow for packaged releases

…OSSIE-Org#130)

- Add koffi@2.15.1 as production dependency
- Add src/server/VirtualInput.ts: platform-native VirtualInputDriver interface
  with Windows (user32.dll SendInput), Linux (/dev/uinput), macOS (CoreGraphics)
  implementations; createVirtualInput() factory selects driver at runtime
- Rewrite move/click/scroll in InputHandler.ts to use VirtualInput; NutJS
  retained only for keyboard actions (key, combo, text, copy, paste, zoom modifier)
- Add InputHandler.cleanup() and call it in websocket.ts on wss close
- Add poc/virtual-input.cjs: standalone runnable PoC (node poc/virtual-input.cjs)
  covering all 9 operations; tested and confirmed working on Windows 10

Closes AOSSIE-Org#130
- poc/virtual-input.cjs: fix run command in header comment (.js -> .cjs)
- VirtualInput.ts: add leftDown/leftUp, rightDown/rightUp, middleDown/middleUp
  for press-only / release-only drag support on all three platforms
- VirtualInput.ts: fix macOS scrollH — use CGEventCreateScrollWheelEvent with
  wheelCount=2 and wheel2 arg so horizontal scroll is no longer a no-op
- InputHandler.ts: click case now respects msg.press (true=down, false=up,
  undefined=full click) enabling drag flows
- InputHandler.ts: wrap vi.init() in constructor try/catch; server startup
  continues with vi=null if virtual device cannot be opened, all vi call
  sites guard against null
- InputHandler.ts: cleanup() cancels pending move/scroll timers and sets
  isShuttingDown flag before destroying the device; timer callbacks guard
  isShuttingDown so no event fires after cleanup
- websocket.ts: replace wss.on('close') (never fires for noServer:true WSS)
  with server.on('close') on the underlying HTTP server so cleanup runs
  reliably on Vite dev server shutdown
- poc/README.md: add architecture diagram, comparison table vs NutJS,
  per-platform run instructions, and operation coverage table
- virtual-input-poc.cjs: standalone PoC (move, click, scroll) on Windows/Linux/macOS
- POC_README.md: quick test instructions + why this approach beats NutJS

Run: node virtual-input-poc.cjs (Linux: sudo node virtual-input-poc.cjs)
…utables

- Add setPermissionRequestHandler and setPermissionCheckHandler to BrowserWindow
  session so getDisplayMedia is not silently denied in packaged builds (Bug AOSSIE-Org#254)
- Add macOS screen recording permission check at app startup
- Add contextIsolation/nodeIntegration webPreferences
- Add macOS activate handler for dock re-open
- Add linux target (dir) to package.json for electron-builder
- Add flatpak/ directory with Flatpak manifest, .desktop file and AppStream metadata
- Add .github/workflows/flatpak.yml CI pipeline for Flatpak distribution (Issue AOSSIE-Org#206)
@coderabbitai

coderabbitai Bot commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

The PR implements a cross-platform virtual input driver using koffi FFI to replace NutJS mouse control, adds Electron permission handling for media and screen capture, introduces Flatpak packaging automation and metadata, and includes PoC documentation and implementation for the new input system.

Changes

Cohort / File(s) Summary
Flatpak Packaging Infrastructure
.github/workflows/flatpak.yml, flatpak/com.rein.app.yml, flatpak/com.rein.app.metainfo.xml, flatpak/com.rein.app.desktop
New GitHub Actions workflow automates Flatpak builds with npm source generation, runtime setup, and artifact publishing. Includes Flatpak manifest with Electron app bundling, desktop entry metadata, and AppStream configuration for application catalog registration.
Virtual Input PoC & Documentation
POC_README.md, poc/README.md, poc/virtual-input.cjs, virtual-input-poc.cjs
Comprehensive PoC documentation and standalone test scripts demonstrating cross-platform virtual input via koffi FFI (Windows SendInput, Linux /dev/uinput, macOS CoreGraphics), including quick-start instructions and platform-specific prerequisites.
Virtual Input Driver Implementation
src/server/VirtualInput.ts
New high-level virtual input abstraction supporting mouse movement, clicks, scrolling, and pinch-zoom across Windows, Linux, and macOS via native OS APIs accessed through koffi FFI. Platform-specific drivers encapsulate SendInput, uinput device creation, and CoreGraphics event synthesis.
InputHandler Refactoring
src/server/InputHandler.ts, src/server/websocket.ts
Replaces NutJS mouse control with VirtualInput driver; adds press semantics to InputMessage; introduces cleanup() method with shutdown guards; wires InputHandler cleanup to HTTP server lifecycle for proper resource release.
Electron & Configuration Updates
electron/main.cjs, package.json
Adds koffi dependency and Linux electron-builder dir target. Electron main process now enables contextIsolation, configures session-based permission handlers for media/display-capture/screen, and adds macOS startup permission warm-up and app activation handler.

Sequence Diagram

sequenceDiagram
    participant Client as Client<br/>(WebSocket)
    participant InputHandler
    participant VirtualInput
    participant OS as OS API<br/>(SendInput/uinput/CoreGraphics)

    Client->>InputHandler: WebSocket input message<br/>(move/click/scroll)
    InputHandler->>InputHandler: Parse & validate<br/>shutdown guards
    
    alt Mouse Movement
        InputHandler->>VirtualInput: moveMouse(x, y)
        VirtualInput->>OS: Emit mouse event
        OS-->>VirtualInput: Success
    else Click
        InputHandler->>VirtualInput: leftClick() / rightClick()
        VirtualInput->>OS: SendInput / write /dev/uinput /<br/>CGEventPost
        OS-->>VirtualInput: Event delivered
    else Scroll
        InputHandler->>VirtualInput: scrollV(delta) / scrollH(delta)
        VirtualInput->>OS: Emit scroll event
        OS-->>VirtualInput: Success
    end
    
    VirtualInput-->>InputHandler: Completion
    InputHandler-->>Client: Ready for next input
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Suggested Labels

Typescript Lang, Documentation

Poem

🐰 Hops and squeaks with trackpad glee,
Koffi brings input wild and free,
Windows, Linux, macOS too,
Platform bridges, fresh and new!
Flatpak bundles seal the deal—
Cross-platform magic, oh so real!

🚥 Pre-merge checks | ✅ 2 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description does not follow the required template structure; it lacks the 'Addressed Issues' section header, functional verification checklist, and required 'Checklist' items. Restructure the description to include Addressed Issues section with issue links, complete Functional Verification checklist for relevant features, and all required checklist items from the template.
Out of Scope Changes check ❓ Inconclusive While most changes align with the linked issues, the PR includes extensive virtual input infrastructure (koffi FFI implementation, VirtualInput driver, virtual-input-poc.cjs, poc/ directory) that appears unrelated to the screen-mirror fix or Flatpak pipeline objectives stated in the PR summary and linked issues. Clarify whether the virtual input driver changes are intended for this PR or should be separated into a distinct pull request, as they significantly expand scope beyond display-capture permissions and Flatpak packaging.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(screen-mirror): grant display-capture permission + Flatpak pipeline' clearly summarizes the main changes: fixing screen mirroring permissions and adding Flatpak packaging support.
Linked Issues check ✅ Passed The PR addresses Bug #254 by adding permission handlers for display-capture/media in Electron sessions and macOS startup checks, directly resolving the reported issue that screen mirroring did not work in executables due to missing permissions.

✏️ 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.

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.

[Bug]: Screen Mirror in Executatbles

1 participant