Skip to content

fix(platform): dispatch BigBox PlayGame calls to WPF UI thread#527

Open
wizzomafizzo wants to merge 8 commits into
mainfrom
fix/bigbox-game-launch-threading
Open

fix(platform): dispatch BigBox PlayGame calls to WPF UI thread#527
wizzomafizzo wants to merge 8 commits into
mainfrom
fix/bigbox-game-launch-threading

Conversation

@wizzomafizzo
Copy link
Copy Markdown
Member

@wizzomafizzo wizzomafizzo commented Feb 7, 2026

Summary

  • Fix game launching in BigBox mode by marshaling PlayGame calls to the WPF UI thread via Dispatcher.Invoke() — the named pipe reader runs on a background thread which causes BigBox to silently fail
  • Capture the WPF Dispatcher during plugin initialization (PluginInitialized, LaunchBoxStartupCompleted, BigBoxStartupCompleted) for reliable access from background threads
  • Add null-conditional operators on ViewModel access to prevent NullReferenceException
  • Call ShowGame() before PlayGame() in BigBox mode so LEDBlinky receives Event 9 (game selection) for the NFC-scanned game — without this, LEDBlinky shows controls for whichever game was highlighted in the BigBox menu
  • Bump plugin version to 1.1.0

Closes #509
Closes #545

Summary by CodeRabbit

  • Chores

    • Version updated to 1.2.0.
    • Build/publish step adjusted to allow restore during publish.
  • Bug Fixes

    • Improved launch lifecycle and BigBox UI handling: prevents concurrent launches, reliably restores or navigates back to the correct view after exit, and re-shows launched games on focus loss.
  • New Features

    • Added BigBox navigation/search/open commands, clearer error reporting, and file-based diagnostics/logging.

LaunchGameById is called from a background thread (named pipe reader),
but BigBoxMainViewModel.PlayGame requires the WPF UI thread. Capture
the Dispatcher during plugin init and use Invoke() to marshal PlayGame
calls onto it.

Closes #509
ShowGame navigates BigBox UI to the NFC-scanned game, firing LEDBlinky
Event 9 (game selection). Without this, LEDBlinky shows controls for
whichever game the user had highlighted in the BigBox menu rather than
the game actually being launched.
Comment thread scripts/windows/launchbox-plugin/ZaparooPlugin.cs Outdated
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: db666769-5aa9-4b7a-822e-7f00d9fee987

📥 Commits

Reviewing files that changed from the base of the PR and between 5fa2be6 and a9059dd.

📒 Files selected for processing (1)
  • scripts/windows/launchbox-plugin/ZaparooPlugin.cs
✅ Files skipped from review due to trivial changes (1)
  • scripts/windows/launchbox-plugin/ZaparooPlugin.cs

📝 Walkthrough

Walkthrough

Assembly/file version metadata bumped to 1.2.0. The LaunchBox plugin rewrites IPC command handling and launch lifecycle (case-normalized dispatch, pending-launch state with 30s stale timeout, UI-dispatcher PlayGame, Win32 focus hook, navigation restore, error reporting, and logging). Dockerfile publish no longer uses --no-restore.

Changes

Cohort / File(s) Summary
Version Metadata
scripts/windows/launchbox-plugin/ZaparooLaunchBoxPlugin.csproj
Updated Version, AssemblyVersion, and FileVersion from 1.0.0 to 1.2.0.
LaunchBox Plugin (major)
scripts/windows/launchbox-plugin/ZaparooPlugin.cs
Reworked IPC command dispatch (case-normalized, new BigBox navigation/search/open-manual commands, ErrorEvent on failures), added required-field validation, introduced pending-launch state with 30s stale timeout to prevent concurrent launches, resolve IDs to IGame/IAdditionalApplication, ensure PlayGame runs on UI dispatcher, add Win32 foreground hook to detect focus and re-show launched game, update GameStarted/GameExited payload mapping to prefer additional apps, add file logging and LaunchBox root capture, and refine startup/shutdown and post-exit navigation (keyboard-back emulation / fallback to ShowAllGames).
Build container
scripts/windows/launchbox-plugin/Dockerfile
Removed --no-restore from the dotnet publish step so publish may perform restore as needed.

Sequence Diagram

sequenceDiagram
    participant External as External Trigger (NFC / IPC)
    participant Plugin as Zaparoo Plugin
    participant Dispatcher as UI Dispatcher
    participant BigBox as BigBox / LaunchBox UI
    participant Game as Launched Game Process
    participant WinEvent as Win32 Foreground Hook

    External->>Plugin: Send command (case-normalized)
    Plugin->>Plugin: Validate command / resolve id -> IGame or IAdditionalApplication
    alt launch already pending
        Plugin-->>External: ErrorEvent (concurrent launch rejected)
    else
        Plugin->>Plugin: Set pending-launch id (30s timeout)
        Plugin->>Dispatcher: Invoke PlayGame(...) on UI thread
        Dispatcher->>BigBox: Optionally show target (FilterType.None) before launch
        Plugin->>Game: PlayGame starts
        WinEvent->>Plugin: Foreground change detected
        Plugin->>Dispatcher: Re-show game in BigBox if needed
        Game-->>Plugin: GameExitedEvent (prefers additional app info)
        Plugin->>Dispatcher: If configured, emulate BigBox back key or ShowAllGames
        Plugin->>Plugin: Clear pending-launch state
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I hopped through lines where commands sleep,

I normalized cases, guarded launches deep.
Dispatcher woke, BigBox found the game,
A focus nudge, a log, and back we came.
Hop, tap, play — the rabbit signs its name.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main focus of the PR: dispatching BigBox PlayGame calls to the WPF UI thread.
Linked Issues check ✅ Passed The PR successfully addresses both linked issues: fixes NFC launching in BigBox (#509) by adding UI thread dispatching, and fixes the post-exit navigation flow (#545) by emulating back-navigation with stale-timeout handling.
Out of Scope Changes check ✅ Passed All code changes are scoped to fixing NFC launch threading and navigation issues; version bumps and diagnostic logging additions are directly related to the core objectives.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/bigbox-game-launch-threading

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

@sentry
Copy link
Copy Markdown

sentry Bot commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/windows/launchbox-plugin/ZaparooPlugin.cs`:
- Around line 116-124: The branch that handles matching pending BigBox restores
leaves the field _shouldRestoreBigBoxView unchanged on the non-match path,
allowing a previously-set true value to persist; update the logic around
MatchesPendingBigBoxRestore(game, app) so ClearPendingBigBoxRestore() is always
called and explicitly set _shouldRestoreBigBoxView = false when there is no
match (or invert the flow: call ClearPendingBigBoxRestore() first and then set
_shouldRestoreBigBoxView = MatchesPendingBigBoxRestore(game, app)) so
OnGameExited() cannot restore BigBox for unrelated launches; refer to the
MatchesPendingBigBoxRestore, ClearPendingBigBoxRestore, and
_shouldRestoreBigBoxView symbols when making the change.
- Around line 531-543: The InvokeOnUiThread method currently executes action()
directly when _uiDispatcher is null, which can run UI work on the pipe
background thread; change this to gate or enqueue the work until a real UI
dispatcher exists: when _uiDispatcher (or Application.Current?.Dispatcher) is
null, do not call action() — instead store the Action in a short-lived queue or
await obtaining the dispatcher (e.g., subscribe to an initialization event or
poll Application.Current.Dispatcher) and then Invoke/BeginInvoke queued actions
on that dispatcher; update InvokeOnUiThread and the _uiDispatcher initialization
path to flush the queue once a valid dispatcher is captured so no UI work runs
on the pipe thread.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 703b965f-ead1-451d-a022-5f041525ad1a

📥 Commits

Reviewing files that changed from the base of the PR and between f9959fd and 1091a52.

📒 Files selected for processing (2)
  • scripts/windows/launchbox-plugin/ZaparooLaunchBoxPlugin.csproj
  • scripts/windows/launchbox-plugin/ZaparooPlugin.cs

Comment thread scripts/windows/launchbox-plugin/ZaparooPlugin.cs Outdated
Comment thread scripts/windows/launchbox-plugin/ZaparooPlugin.cs Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/windows/launchbox-plugin/ZaparooPlugin.cs`:
- Around line 680-689: Before calling
PluginHelper.BigBoxMainViewModel.PlayGame(...) in the branch where BigBox is
running, ensure the NFC-targeted title is selected first; insert a call to the
BigBox selection API on PluginHelper.BigBoxMainViewModel (e.g. SelectGame(game)
or set SelectedGame = game) immediately before Log(...) / PlayGame(...) so the
UI highlight matches the scanned game and LEDBlinky receives the correct
selection; keep EnsureForegroundHook() and BeginPendingLaunch(...) as-is and
then invoke the selection prior to
PluginHelper.BigBoxMainViewModel.PlayGame(game, app, null, null).
- Around line 568-620: For the listed switch branches ("launch", "showplatform",
"showplaylist", "search", "getgamesforplatform") add explicit error reporting
when required fields are missing instead of silently no-op: where you currently
check string.IsNullOrEmpty(command.Id/Platform/Playlist/Query) and skip calling
LaunchGameById, ShowPlatform, ShowPlaylist, Search, or SendGamesForPlatform,
call the IPC error-reporting path to emit an ErrorEvent with a clear message
(e.g., "missing required field 'Id'/'Platform'/'Playlist'/'Query' for <action>")
so callers can distinguish bad input from success; implement this in the
branches referencing LaunchGameById, ShowPlatform, ShowPlaylist, Search, and
SendGamesForPlatform.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 611c4719-a384-4d5f-ac85-c4d478e4d913

📥 Commits

Reviewing files that changed from the base of the PR and between 1091a52 and 5fa2be6.

📒 Files selected for processing (3)
  • scripts/windows/launchbox-plugin/Dockerfile
  • scripts/windows/launchbox-plugin/ZaparooLaunchBoxPlugin.csproj
  • scripts/windows/launchbox-plugin/ZaparooPlugin.cs
✅ Files skipped from review due to trivial changes (1)
  • scripts/windows/launchbox-plugin/ZaparooLaunchBoxPlugin.csproj

Comment thread scripts/windows/launchbox-plugin/ZaparooPlugin.cs
Comment thread scripts/windows/launchbox-plugin/ZaparooPlugin.cs
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.

Exiting game in BigBox leads to game preview screen instead of main view NFC launching not working in BigBox with version 2.9.0 core and plugins

1 participant