Commit Graph

5503 Commits

Author SHA1 Message Date
Bee
f50eacfcbd feat: add browser PICO-8 player
Add v2 browser playback for .p8 and .p8.png cartridges, backed by the
FAKE-08 WebAssembly runtime, with canvas rendering, audio, fullscreen and
keyboard, gamepad, mouse and touch input. Wires up platform detection,
play actions, routing, localization, gallery navigation, play-session
tracking and lifecycle cleanup.

The runtime is fetched in the emulator stage of docker/Dockerfile, pinned
by source commit and verified with sha256, so it is provisioned the same
way as EmulatorJS, Ruffle and js-dos rather than committed to the repo.

DISABLE_PICO8 gates the player, matching the existing DISABLE_EMULATOR_JS,
DISABLE_RUFFLE_RS and DISABLE_JSDOS toggles.

Based on #4383.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-08 17:59:52 -04:00
Georges-Antoine Assi
568aa818de refactor: tighten the library structure naming and docstrings
Rename `FirmwareTemplate.platform_path` to `firmware_dir`: it returns the
firmware folder, while the same name on `StructureTemplate` returns the platform
folder. Name the watcher's index for the segment it points at.

Fold the two reads of a raw structure key into `_raw_template`, and drop the
docstrings that only restated a one-line delegation or a signature.

Remove `footer-create-summary-default`, which no component references and whose
copy still named Structure A.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-08 08:53:55 -04:00
Georges-Antoine Assi
6676011684 fix: let a configured structure template wrap in the setup wizard
The banner and footer chips held either `roms/{platform}` or `{platform}/roms`
before, so their width was bounded. A configured template is not, and a nested
one overflowed its container at every viewport, clipping the path mid-segment.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-08 08:46:28 -04:00
Georges-Antoine Assi
a7ecfd96a9 feat!: make filesystem.structure the single library layout
`filesystem.structure` now spells out the whole layout rather than only the part
below a platform folder. A template is relative to the library root, `{platform}`
marks the platform folder, and `{game}` marks where a game begins.

Merge `{gameFile}` and `{gameDir}` into one `{game}` terminal. The information a
terminal carried was the depth, not the kind: at a declared level a file is a
game of its own and a folder is one multi-file game, which a stat answers. That
drops the two-template idiom for a level holding both, and `_discover_default_roms`
with it, since the default scan is now just `roms/{platform}/{game}`.

Retire the auto-detected `{platform}/roms` layout, along with
`filesystem.roms_folder` and `filesystem.firmware_folder`, which named one path
segment each that a template now contains. Both are refused at startup with the
template that reproduces the layout, so an instance that relied on either says so
instead of scanning an empty library and marking every rom missing. Firmware gets
its own `structure.firmware` key rather than following the rom layout implicitly.

`get_roms_fs_structure` keeps meaning the folder a platform's games start in, so
the `.physical` sentinel paths already in the database still resolve. Per-platform
overrides have to agree with `default` on where the platform folder sits;
relocating one platform needs platform discovery and the watcher to union several
roots, which is left out.

The setup wizard reports `library_ready` plus the configured template instead of
a `struct_a`/`struct_b` discriminator, so the banner shows the layout in force
rather than guessing it client-side.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-08 08:39:21 -04:00
Georges-Antoine Assi
dd7f46b52c fix: make metadata exports and matching follow the library structure
Testing the custom library structure against a live library turned up four
defects, all of them a path being reduced to a bare file name.

Both exporters wrote a rom's `fs_name` alone, so every game a template nests
was exported as if it sat in the platform folder: ES-DE and Pegasus could not
find any of them. They now write the rom's path relative to the platform
folder, the folder the metadata files themselves live in, and copy exported
media into the matching subfolder so two identically named roms keep their own
artwork.

Merging into an existing gamelist.xml / metadata.pegasus.txt keyed entries by
file name too, so identically named roms in different folders both merged into
the first entry and produced duplicates. Entries are now keyed by path, with a
Pegasus block matched by the folder its listed files sit in.

Reading a gamelist.xml had the same collision: two roms sharing a file name
both took the metadata of whichever entry was parsed last. A rom's own path now
wins, and a bare file name stays a fallback key for the tools that write those,
dropped when two entries share it.

Default discovery surfaced hidden folders as multi-file games, unlike
structured discovery which skips them. exclude_multi_roms now owns that rule
for both.

Also validate `exclude`'s exclusion_type: an unknown value reached
`Config.__getattribute__` and returned a 500 rather than a 422.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-08 07:31:05 -04:00
Georges-Antoine Assi
6b01e9943e refactor: trim review-pass comments and cover LocationChip
Cut the comments that explain rather than note: the migration's four-paragraph
docstring, the upload-path and digest-SQL docstrings, and the mark-missing note
in the scan loop. Drop an em-dash from LocationChip's header per CLAUDE.md.

Reword 0126's downgrade error so it no longer embeds a SELECT, which bandit
reads as string-built SQL, and mark the dialect-selected backfill nosec B608 the
way the other migrations do.

Add the LocationChip test its HashChip sibling already had, covering the copy
going through useClipboard (the composable is what applies the secure-context
guard).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 20:17:28 -04:00
Georges-Antoine Assi
f105622513 fix: address code review on the library structure unique index and relocation
Key the unique roms index on a sha256 digest of the full path. Indexing
(platform_id, fs_path, fs_name) directly is 5804 bytes of utf8mb4, which MySQL
rejects with ER_TOO_LONG_KEY and MariaDB silently demotes to a hash index; the
digest column keeps it a 260-byte BTREE on every supported driver. It is derived
by the same @validates hook that maintains the other fs_name columns, and
resynced explicitly in update_rom and convert_rom_to_folder.

Migration 0126 backfills the digest in one dialect-branched UPDATE. A Python
executemany right after the ADD COLUMN silently applies only its first parameter
set on mariadb-connector, leaving the rest NULL. test_migrations pins the SQL
expression to compute_full_path_hash so the two cannot drift.

Drop the relocation pre-pass. mark_missing_roms already runs before the identify
loop, so a moved file reaches get_matching_missing_rom, which requires all three
hashes to agree (or a title_id, covering non-hashable platforms), refuses
ambiguous matches, re-parses filename tags and emits over the socket. The
pre-pass duplicated it with a weaker CRC-only check, hashed every candidate
twice, compared folder sizes against a total that excludes filtered files, and
ran on QUICK scans.

Send uploads to a folder the platform's structure will actually discover, so the
next scan does not flag a fresh upload as missing, and refuse with a 400 when
only the user can pick the folder.

Make 0126's downgrade refuse when duplicate file names exist instead of deleting
the roms (and their saves, notes and collection membership) that carry them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 19:14:58 -04:00
Georges-Antoine Assi
9dcaf89890 fix: address PR review feedback on library structure and relocation
A grouping folder is no longer also a game. With `{gameDir}` and
`{category}/{gameFile}` declared together, the category folder was surfaced
as a multi-file game *and* descended into, listing its contents twice. A
folder any template descends into is now treated as a grouping level.

Relocation runs for every platform, not only those with a custom structure.
Dropping a platform's template moves every game back to the platform root,
which previously read as a library of new games and orphaned all the saves,
play history, favorites and collection membership. A library whose paths are
unchanged still costs one query and no hashing. This also removes the need
for a manual "apply relocation" toggle.

Physical games are excluded from relocation candidates: they have no file, so
they read as having disappeared from their path on every scan.

A near-miss on the terminal macro (`{gameFolder}` for `{gameDir}`) now names
the offending section instead of only reporting a missing terminal.

Documents two limits the QA pass asked about: a move that also compresses or
extracts the game changes its size and is not detected (the size pre-filter
runs before hashing), and how reverting to the default layout behaves.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 17:01:33 -04:00
Georges-Antoine Assi
4219f56f10 Merge branch 'master' into claude/kind-goodall-0b77y7
Conflict resolution notes:

- Locale rom.json: master sorted and reworked every file; took master's and
  re-inserted `location` / `location-copied` in sorted position. Added them to
  the new tr_TR locale.
- FSRom gained a required `fs_path`, so `build_hashless_fs_rom` now takes one
  and both call sites pass the rom's own path.
- `get_roms` keeps this branch's `_collect_fs_roms` discovery while adopting
  master's one-pass build and in-place sort.
- `mark_missing_roms` takes full paths and now also excludes physical games
  (master), and the scan loop keeps master's early missing-sync plus its
  restored-rom emit alongside this branch's relocation pass. The relocation
  filter now applies only to the identify loop, so a relocated rom is no longer
  re-flagged missing at the end of the scan.
- Relocation writes rom files through master's `sync_rom_files` (which replaced
  `purge_rom_files` / `add_rom_file`), so row ids and track metadata survive.
- Master's unique index on (platform_id, fs_name) contradicts this branch's
  premise that same-named files in different folders are distinct games.
  Migration 0126 widens it to (platform_id, fs_path, fs_name); physical games
  all share one folder, so a duplicate title is still rejected.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 16:24:59 -04:00
Georges-Antoine Assi
8fec86caa3 refactor(player): compare save bytes instead of hashing them
Change detection needs equality, not a fingerprint, and the hash was the
only reason the tick handler was async. Comparing bytes drops the WebCrypto
call, its non-secure-context fallback, and both mid-flight liveness checks
the awaits had made necessary: the decision now runs before the upload with
nothing suspended in between.

Seeding reads the SRAM with getSaveFile(false), which skips the dump that
was firing a saveSaveFiles tick, so the subscription no longer has to be
ordered below it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 12:00:06 -04:00
Georges-Antoine Assi
80a9c98979 refactor(player): one gate for the save sync subscription
The active flag and the install slot both said "this component still owns
the subscription", so the slot alone now carries it.

fnv1a64's second lane re-hashed the same bytes offset by one with the same
prime, leaving the halves correlated; distinct primes over a single load
drop the per-byte modulo too.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 11:44:05 -04:00
Georges-Antoine Assi
f8e770d1b4 fix(player): keep an in-flight save sync from outliving the gate
A tick that is mid-hash when Exit or Save & Quit closes the gate would
still issue its own upload and race theirs. Teardown during the seed
likewise re-armed the gate and subscribed to a dead emulator.

displayMessage now tolerates a torn-down emulator for all of its callers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 11:26:02 -04:00
Georges-Antoine Assi
818a52f892 docs(player): trim the save sync comment to the part the code can't say
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 11:12:17 -04:00
Georges-Antoine Assi
d2497ac05f fix(player): register the save sync handler at most once per emulator
EmulatorJS exposes no `off`, so a second EJS_onGameStart against one live
emulator would leave two handlers with independent trackers uploading the
same tick.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 11:09:18 -04:00
Georges-Antoine Assi
7b2baaa545 refactor(config): rename EJS_AUTO_SAVE_SYNC to EJS_ENABLE_AUTO_SAVE_SYNC
The config.yml key (emulatorjs.auto_save_sync) is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 11:08:02 -04:00
Georges-Antoine Assi
1443f66cf5 Merge branch 'master' into feat/auto-save-sync 2026-09-07 10:24:48 -04:00
Georges-Antoine Assi
17bd4207a0 Merge remote-tracking branch 'origin/master' into claude/igdb-keywords-themes-perspectives 2026-09-06 18:48:46 -04:00
Georges-Antoine Assi
d84fa1101e fix(recommendations): guard the vote count and the similar-games auth
The rating-count column cast whatever `total_rating_count` held straight to
a number, without the digit guard every other numeric branch in the
migration carries. The metadata blobs are writable verbatim through the raw
metadata form, so a library holding a non-numeric value could not migrate at
all: PostgreSQL aborts the ALTER TABLE on `invalid input syntax for type
numeric`. The MariaDB branch also reached for JSON_VALUE, which MySQL only
gained in 8.0.21, below the 8.0 the docs advertise.

`/roms/{id}/similar` was gated behind DISABLE_DOWNLOAD_ENDPOINT_AUTH while
resolving permissions unconditionally, so with that flag set an anonymous
request hit `UnauthenticatedUser.role` and 500'd. It is not a download
endpoint; it now requires ROMS_READ, as /api/recommendations does.

The details page also fetched similar games with the feature switched off,
and OverviewTab took a `webp` prop for state it already reads from
useWebpSupport.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 16:40:12 -04:00
f0rthelulz
8af8ca8735 docs(player): the seed fires a save tick, so the subscription stays below it 2026-09-06 14:18:08 -05:00
Georges-Antoine Assi
e78a4aa1b9 chore(recommendations): cut the comments back to what the code cannot say
The engine carried its tuning history in its comments: measurement logs for
PIVOT_B, the weight a facet held before the company split, the shape of the
cold-start feed before the Bayesian average. None of that describes what the
code does now, and it belongs in the history rather than beside the values.

Also folds serving's ROM loader into feed's, which differed only by the
visibility filter applied afterwards.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 14:35:15 -04:00
f0rthelulz
949d0e0adb fix(player): review fixes for periodic save sync
Fall back to a JS hash when WebCrypto is unavailable (non-secure
contexts) and never let a hash or upload error escape the emitter or
the game-start hook. Comments trimmed to the style guide (no em-dashes,
one or two lines of why).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-06 12:19:59 -05:00
f0rthelulz
e1e4663521 feat(player): optional periodic upload of changed save files
Behind a new config flag, emulatorjs.auto_save_sync (default false), the
EmulatorJS player uploads the in-game save (.srm) to the server on
EmulatorJS' own "System Save interval" tick, without Save & Quit.

EmulatorJS already runs that timer (default 300 s) and its
gameManager.saveSaveFiles() fires a "saveSaveFiles" event carrying the
SRAM bytes, but nothing listens to it, so today an in-game save reaches
the server only from Save & Quit or the Export Save File button (#4201).
This subscribes to that event from Player.vue and uploads through the
existing saveSave() when the SRAM hash is unchanged since the previous
tick (a save the core is still writing is never uploaded — the corruption
the earlier automatic upload was removed for, #2349) and differs from the
last upload (an idle session uploads nothing). The tracker is seeded from
the SRAM the core holds after the server save is applied, so a launch
never uploads the server's own file back, and the subscription is turned
off before Save & Quit, Quit and unmount.

The bytes EmulatorJS hands out are views onto the emulator heap, a
SharedArrayBuffer on threaded cores; they are copied into a plain
ArrayBuffer before hashing or uploading.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-06 11:37:33 -05:00
Georges-Antoine Assi
5bce1215ce refactor(recommendations): deepen four fixes to their root cause
Merge 0123/0124/0125 into one migration. Each added STORED generated
columns to `roms`, and 0125 already dropped and re-added several, so
upgrading rewrote the widest table three times and restated the
`roms_metadata` view three times. One ALTER TABLE now carries the Steam
rebuild, the three IGDB tag columns and the rating count, and the view is
recreated once. Verified upgrade/downgrade/upgrade on MariaDB and Postgres.

Score each unordered pair once. Candidate generation is symmetric, so
every pair had its dot product computed twice. The sweep now runs in
ascending id order and scores only from the lower id, which also makes a
ROM's edges final the moment the sweep passes it, so the incremental
flush survives. Only the target's quality bonus differs by direction, so
one content score is blended twice. The per-ROM candidate ceiling moves
into `candidate_ids`, taking the rarest posting lists first, where it
bounds work instead of being applied after the cost was already paid.

Read identity off one list. `sibling_roms` decides "same title" from
seven provider ids; the suppression here used two, so a pair matched only
by MobyGames was a sibling everywhere else in RomM and a recommendation
for itself here. `IDENTITY_ID_FIELDS` on the model is now the one home,
consumed unscoped by the builder since a reissue on other hardware is no
more a suggestion than a second copy on the same platform.

Make the facet vocabulary a StrEnum. It was spelled out in five places,
two of them already stale, and `facet: str` kept it out of the API
contract, so an unmapped facet silently rendered a raw value. It reaches
OpenAPI as a closed union and the frontend maps are keyed by it, so
adding a facet now fails the typecheck until the UI handles it.

Give each surface one serving entry point. `similar_roms` and
`recommended_roms` own the over-fetch, hydration, visibility filter,
series cap and cache that the two endpoints and the inspection tool each
re-implemented with three different over-fetch constants; the cache moves
in with them so no caller can rank a feed without populating it.
Endpoints now do ORM-to-schema only.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 12:12:52 -04:00
Georges-Antoine Assi
1ff9944224 refactor(recommendations): reuse, simplification and efficiency pass
Backend, wasted work:
- `_score_one` computed `content_similarity` twice per candidate on the
  trim path and built `shared_reasons` for every candidate clearing the
  score floor, discarding almost all of them. Compute content once and
  build reasons only for the edges actually stored.
- `get_feature_rows` outer-joined `RomMetadata`, a view over the wide
  `roms` table, defeating the point of reading the narrow facet mirror.
  Read the generated columns off the `Rom` join already present.
- Feed cache invalidation ran a keyspace SCAN on every `rom_user` write.
  Put graph and per-user version counters in the key so it is one INCR,
  matching `invalidate_filter_values_cache`.

Backend, reuse:
- Route the five name comprehensions beside `_expanded_names` through it.
- `_recency_factor` reimplemented `to_utc`.
- `replace_similarity_edges` hand-rolled `itertools.batched`.
- Derive `TASTE_FACETS` from `FACET_WEIGHTS` instead of restating its keys.

Backend, dead code:
- `ScoredNeighbour`, `BuildStats.to_dict`, `delete_all_similarity_edges`,
  the unread `difficulty`/`completion`/`backlogged` affinity fields,
  `FACET_ORDER` and `RomInfo.rom_id`, and a no-op `column_type` ternary.

Frontend:
- Extract `RecommendationReason` from the two byte-identical copies in
  `Home.vue` and `SimilarGamesGrid.vue`, dropping the repeated
  `primaryReason` calls and their non-null assertions.
- Cap the caption with `--r-card-art-w` rather than a `158px` literal that
  does not track the per-breakpoint card width.
- Key the similar-games fetch on the ROM id: `watchEffect` refetched on
  every optimistic mutation of `currentRom`.
- One home for the similar-games limit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 11:44:00 -04:00
Georges-Antoine Assi
c31e4f6935 Merge pull request #4369 from rommapp/fix/no-reload-during-active-play
fix(v2): don't reload the page on reconnect while a game is running
2026-09-06 10:31:41 -04:00
Georges-Antoine Assi
4cbdc29c46 Merge pull request #4373 from rommapp/feat/v2-cover-zoom-and-lightbox-backdrop
feat(v2): zoom the game cover, and dismiss the lightbox from anywhere on the backdrop
2026-09-06 10:30:21 -04:00
Georges-Antoine Assi
b73cd0fae8 style(v2): stand the artwork assets on a shelf instead of in grey slabs
The uniform 16/9 cells letterboxed every asset into an identical tinted
box, so a 42x680 box spine and a 2:1 marquee both read as mostly empty
background. Assets now keep their real proportions under a shared height
cap and sit on a common baseline, with a drop-shadow that follows the
artwork's own silhouette (most scans are transparent PNGs) and a lift on
hover.
2026-09-06 10:11:22 -04:00
Georges-Antoine Assi
6cba1d2494 feat(v2): list the cover in the artwork gallery instead of zooming it
The details cover goes back to being inert. The Media tab's Artwork
subtab now leads with the rom's own cover, so every piece of artwork the
page holds sits in one grid and one lightbox.
2026-09-06 09:55:53 -04:00
Georges-Antoine Assi
29de40f28d style(v2): drop the em-dashes, and the no-op click in the inert-cover test
Review follow-ups. CLAUDE.md bans em-dashes in anything we write, and
Vue Test Utils already refuses to dispatch on a disabled button, so the
click asserted nothing the surrounding expectations did not.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 08:54:24 -04:00
Georges-Antoine Assi
9627d8d950 fix(v2): zoom the cover artwork that is actually on screen
GameCover swaps to the external `url_cover` when the primary image fails,
but the zoom re-resolved the chain itself and kept pointing at the failed
URL — clicking a visible fallback cover opened broken artwork.

Have GameCover expose the src it is rendering and ask it at click time, so
there is one home for "which artwork is on screen". The affordance keys off
`hasArtwork`, which is the separate question of whether there is anything
to zoom into at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 08:51:57 -04:00
Georges-Antoine Assi
8792e51ee5 refactor(v2): give the search pivot one home
GameHeader and InfoGrid each built the same search location object; move
it to a shared `searchLocation` util so the query schema lives in one
place.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 08:46:47 -04:00
Georges-Antoine Assi
3eeda1f210 fix(v2): dismiss the lightbox from anywhere on the backdrop
Only the outer wrapper and the stage dismissed on click, but the item box
between them fills the stage while the image letterboxes inside it. At
1440x900 the item measured 1280x774 against a 421x680 cover, so nearly
everything that read as backdrop was the item div and swallowed the
click. Give the item its own .self handler; the image itself still keeps
the lightbox open.

Fixes #4362

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 08:39:52 -04:00
Georges-Antoine Assi
b58e0c2306 feat(v2): open a lightbox when the game cover is clicked
The details page cover was inert in the v2 UI. Clicking it now opens the
same fullscreen RCarousel lightbox the screenshot and artwork grids use,
sourced from the resolution GameCover already runs so the zoom shows
whatever artwork is on screen (box art, physical, mix image).

A magnify hint fades in on hover and focus, and stays visible on touch
and gamepad where there is no hover. A rom with no artwork at all keeps
its procedural placeholder and the hero stays inert. The 3D box hero is
untouched: it is already interactive.

Closes #4361

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 08:39:44 -04:00
Georges-Antoine Assi
a1c3b7f476 feat(v2): make game header tags clickable
Region, language and custom tags in the details header now link into a
filtered search, the same pivot the Overview info grid already offers on
genres, companies and franchises.

Closes #4363

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 08:34:19 -04:00
Georges-Antoine Assi
7d2822ef6f fix(v2): wait for a quiet network before the held-back refresh
Leaving a player fires teardown requests the reload would abort (the
stream save + release among them), and the backend can drop again while
the refresh waits. Trigger the refresh off the api layer's
`network-quiesced` event, capped for an app that has gone silent, and
skip it when the connection is gone again so the next reconnect handles
it instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 08:30:53 -04:00
Georges-Antoine Assi
add6a16aab fix(v2): don't reload the page on reconnect while a game is running
The reconnect recovery refresh fired on every offline -> online
transition, so a transient network blip during play tore down the page
and killed the running emulator along with any progress it had not
synced yet.

Hold the refresh back while the playing store reports an active session
and run it once the player is left, after a short grace period so the
player's teardown requests reach the backend first.

Fixes #4356

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 08:24:39 -04:00
Sam Dornan
8494744ee7 Merge branch 'master' into claude/igdb-keywords-themes-perspectives
Resolve conflicts in the v2 Home view and its test: keep both the
recommendations row from this branch and the live multiplayer sessions
row from master.

Master added migrations 0119 through 0121 that forked the Alembic chain
against this branch's 0119 through 0122. Renumber this branch's
migrations to 0122 through 0125 so they chain after 0121_state_disc_file.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D9EiQ8VWDJfzhEViDdj84d
2026-09-06 00:24:13 +00:00
Georges-Antoine Assi
7443b690be fix(streaming): keep the container's answers inside its own origin
A broker's launch, join and desktop replies name the URL the browser loads
in an iframe, and urljoin keeps an absolute (or `javascript:`) URL verbatim,
so a container that answered with one could run script in RomM's origin
instead of its own. The three sites now share one resolver that drops a room
URL leaving the configured host, the stage refuses a source that is not
http(s), and the frame is sandboxed without allow-top-navigation so a
container page cannot steer the tab it sits in.

Also drop the shared secret from the config entry a resolution warning
prints, which named the misconfigured container by dumping it whole.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 14:53:43 -04:00
Georges-Antoine Assi
e85fce8e80 fix(streaming): close the holes a review pass found
Session ownership and lifecycle, mostly around who a teardown belongs to:

- file the exit state, save states and state frames under the session's
  owner rather than the caller, so an admin driving someone else's session
  no longer collects their saves
- beat the heartbeat from the admin desktop view, which the stale sweep was
  tearing down three minutes in
- take the claim through release_own_session when a launch aborts, instead
  of deleting a key another player may already hold
- require the same claim to stamp a launch, so a late activate cannot revive
  a drain marker with a six hour TTL
- pull the in-game save archive on every teardown path, not just the two
  that remembered to
- skip draining keys in the admin force-release sweep

Plus: pool members must share a protocol, since the head's capabilities are
what the frontend renders; a claim clears terminations across the whole pool;
multiplayer is only recorded where the broker can actually seat a joiner; and
an unserializable config no longer caches forever on a repr() that repeats.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 14:33:44 -04:00
Georges-Antoine Assi
eccafd13d1 refactor(streaming): polish pass over the new modules
- The five new modules each defined `log = logging.getLogger("romm")`, which is
  what `logger.logger` already exports; they import it now.
- `ACK_TIMEOUT` had two homes. It is a protocol fact, so `protocol.py` owns it
  and the endpoint imports it from there; the unused
  `BROKER_LOAD_STATE_TIMEOUT` copy goes.
- Module and function docstrings trimmed to what the code cannot say: the
  change history and the justifications belong in the commit messages they came
  from.
- `asset_store` takes the union `write_file` accepts rather than `Any`.
- Four hand-rolled `setInterval` pairs (presence beat, session poll, exit
  chord, live sessions, activity tick) become `useIntervalFn`, which also
  cleared a real gap: the presence composable's timer had no scope teardown.
- The launch pushes are matched on the container the claim's 202 named, not on
  the platform: a pool serves one platform from more than one container, so a
  second tab could otherwise act on the first's launch.
- Test helpers typed: the push capture and the resume-claim tuple carry real
  types, and an unused `_claim_ready` helper goes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 13:13:02 -04:00
Georges-Antoine Assi
74c77d0bb2 feat(streaming): answer the claim before the launch, and push what happens
`POST /streaming/sessions` blocked for up to STREAMING_LAUNCH_TIMEOUT (10
minutes) while a broker unpacked a pkg or archive, and four mechanisms existed
to keep that survivable: a 3s status poll the client ran alongside it purely
for progress, `launch_timeout` shipped through /config so the client could size
its own axios ceiling, and a cancel-then-undo branch that re-released a session
the player had already abandoned, because a blocking POST cannot be cancelled.

The claim now answers 202 as soon as the container is reserved and everything
that can fail synchronously has (404, 409, 428 are all still the claim's own
status). The launch runs detached and pushes to the user room the
force-release notice already used:

- `streaming:launch-ready` carries the room URL and the resume outcome
- `streaming:launch-failed` carries the reason; the claim is already freed
- `streaming:launch-phase` carries the broker's extraction phase

The backend polls the broker for that phase itself, once, however many tabs are
watching, and only pushes changes. `GET /sessions/{platform}/status` stays as
the fallback for a tab that missed a push.

That retires the client's launch poll, the `launch_timeout` plumbing and the
cancel-then-undo branch. Leaving during a launch is now just a release, and the
launch-ready handler hands the container back if the player has already gone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 12:04:58 -04:00
Georges-Antoine Assi
1e716b381d feat(streaming): give the streaming routes typed responses
Every streaming route returned a bare `JSONResponse`, so none of their shapes
reached the OpenAPI schema and `services/api/streaming.ts` hand-maintained a
parallel copy of all eleven of them. A response-shape change was a silent
frontend break with nothing to catch it.

`endpoints/responses/streaming.py` declares the shapes and the routes return
them, so they generate like every other endpoint. The 428 a claim raises when a
container still holds an undecided memory card is declared too, through
`responses=`, rather than staying an undocumented `detail` dict.

The frontend types are regenerated and the hand-written interfaces become
aliases onto them. The typecheck immediately found two places they had already
drifted: the hand-written `PlatformCapabilities` was missing `has_memory_card`,
and `LiveSessionCard` passed a possibly-undefined host username where a
nullable string was expected. The termination notice had drifted on the backend
side too: it records `ended_at`, `rom_id` and `rom_name`, which the first draft
of the schema did not carry.

Releasing a session now hands its teardown to FastAPI's `BackgroundTasks`
rather than attaching it to a hand-built response, which is what lets the route
return a model.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 11:15:36 -04:00
Georges-Antoine Assi
3cacb59ee4 refactor(streaming): give the duplicated rules one home each
Backend:
- One session-scan iterator (`_iter_session_keys` / `_iter_live_sessions`)
  replaces three copies of the Redis scan-and-decode loop, and
  `_get_live_session` replaces five independent "a drain marker is nobody's
  session" checks.
- `_abort_claim` replaces seven inlined claim-abort cleanups, so a new failure
  branch can no longer wedge a container and orphan a blank card.
- `_quiesce_container` and `_collect_exit_state` replace the stop-evacuate-wipe
  and guarded state-pull blocks written out in all three teardown paths. The
  `_record_termination` calls stay at the call sites: the three order it
  differently and each has its own reason.
- `_hold_reservation` / `_drop_reservation` collapse the two
  release-after-state-pull helpers into one, and absorb the third copy of that
  branch inlined in the released-session teardown.
- `_load_state_broker`'s two protocol branches were byte-identical, so it now
  takes its route from `_transfer_route`; `_raise_broker_http_error` and
  `_raise_broker_unreachable` replace the error translation copied into
  `_call_broker` and `_webstation_activate`.
- `_container_labels` builds the label map once per request rather than
  re-reading and re-parsing config.yml for every listed row.
- The joinable listing fetches each ROM once, through `get_rom_simple` rather
  than the `@with_details` query, for five columns.
- `store_memory_card_version` hands the hash it computed in memory to the scan,
  which was reading the archive back off disk to recompute it.
- `_prune_state_history` takes the history its caller already fetched.
- `playlist_files` in utils/m3u.py is now the one home for "which files are
  discs", shared by the download endpoint, the m3u generator and the swapper.

Frontend:
- `useActivityPresence` replaces the presence block copied verbatim from
  EmulatorJS.vue into Stream.vue.
- `MemoryCardNameDialog` replaces three copies of the same name-entry dialog.
- The two private axios error extractors give way to the `errorMessage` util,
  three hand-rolled spinners to `RSpinner`, six manual listener pairs to
  `useEventListener`, and five copy-on-write Set/Map trackers to `reactive`.
- `keepaliveHeaders` moves next to the interceptor that owns the CSRF header.
- The exit chord polls at 10Hz instead of every frame, the stage measures its
  offset once instead of per mousemove, `postToStream` reuses the frame list
  the attach pass walked, and the admin/home polls skip a hidden tab.
- `containerLabelForPlatform` on the store replaces the two `streamLabel`
  definitions that answered differently, and the stream/join action labels move
  onto useGameActions so the button and the menu cannot word them differently.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 08:54:32 -04:00
Georges-Antoine Assi
15233afcb1 Merge branch 'master' into feat/streaming-webstation
Conflicts and how they were resolved:

- `useGameActions`: master renamed `useCanPlay`'s `canPlay` to `canPlayLocal`
  and kept a local `canPlayStream`, while this branch moved `canPlayStream`
  into `useCanPlay` and folded it into `canPlay`. Kept this branch's shape and
  took master's `useScanTrigger()` call.
- `Player/Stream.vue`: kept this branch's force-release and session-poll block,
  and re-placed master's `useUnloadGuard(sessionActive)` next to the
  `sessionActive` watch.
- `locales/*/play.json`: kept both sides' keys, re-sorted.
- `__generated__/index.ts`: kept both sides' model exports, re-sorted.
- `test_config_loader.py`: kept both sides' tests.

Master took 0114 through 0118 while this branch was open, so its three
migrations are renumbered 0119-0121 and rechained after
`0118_rom_category_cheat_pg`, leaving alembic with a single head.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 07:49:12 -04:00
Georges-Antoine Assi
76f0fc6cd8 i18n: mention the collections page in the autogenerated toggle
The en_US/en_GB description gained the collections page; carry that into
the other 16 locales so the toggle doesn't describe two of its three
surfaces everywhere but English.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:08:58 -04:00
Georges-Antoine Assi
4166ca6477 test(collections): pin the ?kind=virtual reset to the URL
The fallback test only read the rendered list, so it passed whether the
view cleared the query param or merely reset its local filter, and it
seeded the preference before mount so the runtime flip went uncovered.

Hold the setting in a live ref the tests can flip after mount, assert the
router.replace that drops the param, and add the turn-it-off-while-
filtered case.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:08:13 -04:00
Spinnich
69501c00a8 fix(collections): honor "Show autogenerated collections" on /collections
The v2 collections index fetched and rendered virtual collections
regardless of the `showVirtualCollections` UI setting, so users who
turned the toggle off still got them on the page the v2 UI makes the
primary home for collections. The v2 home page already gates on it,
leaving the two sibling views disagreeing about the same preference.

Read the setting (and the virtual collection type) from useUISettings
rather than raw localStorage, skip the fetch and the list entries when
it is off, drop the virtual option from the toolbar's kind cluster, and
snap a stale `?kind=virtual` back to `all`.

Fixes #4348

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:31:40 +00:00
Georges-Antoine Assi
5837ac3df9 refactor(config): name the two default dir lists for what they exclude
DEFAULT_EXCLUDED_DIRS only ever seeded EXCLUDED_PLATFORMS, but its name
implied it was the general directory list, which is how the media folders
came to be added to it in the first place. Rename it and its superset to
DEFAULT_EXCLUDED_PLATFORM_DIRS and DEFAULT_EXCLUDED_MULTI_FILE_DIRS, and
spell out what a multi-file ROM is.

DEFAULT_EXCLUDED_FILES and DEFAULT_EXCLUDED_EXTENSIONS keep their generic
names: each still feeds both a single-file and a multi-file-parts exclusion.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 16:42:43 -04:00
Georges-Antoine Assi
65b2a050c1 refactor(gamelist): give the ES-DE media folder names one home
Fold the exporter's folder map and the importer's ESDE_MEDIA_MAP into a
single GAMELIST_MEDIA_DIRS, so writing, reading and skipping a media type
is one edit. This also picks up thumbnails/, which the scan exclusions were
missing, and drops the hand-appended "images" literal.

Serve the multi-file defaults pre-unioned as DEFAULT_EXCLUDED_MULTI_DIRS so
neither UI has to re-join two lists; v1 was still mapping EXCLUDED_MULTI_FILES
to DEFAULT_EXCLUDED_DIRS and rendering the media dirs as deletable.

Collapse the per-tag asset loop and the bespoke <mix> block into one table
keyed by tag, and skip fnmatch for the exclusion patterns that hold no glob
characters, now that the multi-file list is more than twice as long.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 16:19:55 -04:00
Georges-Antoine Assi
aff25e5013 Merge branch 'master' into claude/github-issue-4226-eab53e 2026-09-04 16:06:33 -04:00