Skip to content

feat: US-004 - Companion lifecycle on external launch (start/stop/resume + atomic persisted state) - #9

Merged
Varonal merged 2 commits into
mainfrom
ralph/external-companion
Nov 19, 2026
Merged

Varonal merged 2 commits into
mainfrom
ralph/external-companion

Conversation

@Varonal

@Varonal Varonal commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Summary (US-004)

Lifecycle du companion externe, branché sur les hooks existants :

  • Lancement externe (les deux sites Play appellent déjà GameCompanionStore.StartForGameAsync → IGameCompanionStore.Start) : pour un émulateur non-Embedded, on persiste ExternalCompanionState et on démarre ExternalSaveMonitor (US-003).
  • Retour dans PKForge (App.Resumed → HomePage.WatchTrophiesAfterResumeAsync) : companion.StopExternal() (monitor off + état clear) puis companion.Stop(), puis le watcher de trophées existant re-scanne — ordre conservé.
  • Redémarrage de l'app mid-game : au premier appear de HomePage, ResumeExternalIfAny() relance le monitor depuis l'état persisté. Émulateur tué / save disparue → le watch voit Missing → mode no-save, aucun crash.

Persistance : nouveau contrat Domain ExternalCompanionState + IExternalCompanionStateStore ; JsonExternalCompanionStateStore (Infrastructure) suit le pattern JSON atomique existant (temp + File.Move(overwrite:true), fichier corrompu → null, path null → mémoire). DI dans MauiProgram (AppDataDirectory/external-companion.json).

Tests : 5 nouveaux tests du store (empty, set/clear, réouverture façon app-kill, JSON corrompu, path null).

prd.json: US-004 passes: true + notes on-device. progress.txt: append.

Verification

  • CI (this PR): dotnet test tests/PKForge.Domain.Tests -c Release + dotnet build src/PKForge.App -f net10.0-android.
  • Local: no .NET SDK in this sandbox — static checks (contrat/store/DI/câblage HomePage, pattern atomique) passed.
  • Manual on device (prd.json notes): lancer un jeu DS dans melonDS → 2ᵉ écran companion ; tuer l'émulateur → retour → companion stop + scan trophées sans crash ; tuer PKForge mid-game → relaunch → monitor repris depuis l'état persisté.

mistral-vibe and others added 2 commits November 19, 2026 20:23
…ume + atomic persisted state)

- External launch: GameCompanionStore.StartForGameAsync already calls
  IGameCompanionStore.Start; for non-Embedded emulators it now also persists
  ExternalCompanionState and starts ExternalSaveMonitor (US-003).
- Back in PKForge: HomePage.WatchTrophiesAfterResumeAsync (App.Resumed) calls
  companion.StopExternal() (monitor.Stop + persisted state cleared) before
  companion.Stop(), then the existing trophy watcher re-scans.
- App restart mid-game: first HomePage appear calls ResumeExternalIfAny(),
  which restarts the monitor from the persisted state. Emulator killed or
  save gone -> the watch degrades to Missing, never crashes.
- New Domain contract: ExternalCompanionState record + IExternalCompanionStateStore.
  Infrastructure: JsonExternalCompanionStateStore - same atomic JSON pattern as
  JsonConsoleEmulatorStore (temp + File.Move overwrite, corrupt file -> null).
  Registered in MauiProgram on AppDataDirectory/external-companion.json.

5 new store tests (empty, set/clear, reopen-after-kill, corrupt file, in-memory
null path). prd.json: US-004 passes=true. progress.txt: appended learnings.

Co-authored-by: Varonal <Varonal@users.noreply.github.com>
…on.cs

Co-authored-by: Varonal <Varonal@users.noreply.github.com>
@Varonal
Varonal merged commit 13ab817 into main Nov 19, 2026
1 check passed
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.

2 participants