feat(events): add the position, playback-failure and play-count events

Three events the frontend had no way to learn about:

- `PlaybackPositionChanged` carries `player.PositionInfo`, so the seek
  bar can render what the player is doing instead of counting seconds
  itself.
- `PlaybackFailed` carries the file and the reason, from both the load
  and the play path, so a track that will not play stops being a
  silent no-op.
- `TrackPlayCountChanged` carries everything needed to patch one track
  in place. `TrackMetadataChanged` means "the tags on disk were
  rewritten" and costs the frontend its entire library cache; finishing
  a track used to emit it.

An event's cost is part of its meaning, and the expensive one must not
be reused for something cheap.
This commit is contained in:
2026-08-12 01:17:41 -04:00
parent fcf2fe509e
commit 55aa3ea5b0
2 changed files with 55 additions and 1 deletions
+21 -1
View File
@@ -8,6 +8,8 @@ export const Events = {
SeekFailed: "SeekFailed",
VolumeChanged: "VolumeChanged",
MuteChanged: "MuteChanged",
PlaybackPositionChanged: "PlaybackPositionChanged",
PlaybackFailed: "PlaybackFailed",
// Queue events (backend → frontend push)
QueueChanged: "QueueChanged",
@@ -49,10 +51,28 @@ export const Events = {
LibraryRenamed: "LibraryRenamed",
LibraryRemoved: "LibraryRemoved",
// Tag writing events
// Tag writing events.
//
// TrackMetadataChanged means "tags on disk were rewritten", and the
// frontend answers it by throwing the whole library cache away and
// refetching — which is correct, because a retag can change an album
// name, an artist, a genre, and therefore every derived collection.
//
// It must therefore not be reused for anything cheaper. Finishing a
// track used to emit it, so every song cost a full refetch: ~37 MB
// across the IPC per track at 50 000 tracks, and the user's track
// selection cleared while music played (audit perf.C1/C2). That is
// what TrackPlayCountChanged below exists to separate
TrackMetadataChanged: "TrackMetadataChanged",
BatchWriteProgress: "BatchWriteProgress",
// Play statistics events.
//
// TrackPlayCountChanged carries everything needed to patch the one
// track in place, precisely so no consumer has any reason to invalidate
// a collection: {audioFileId, filePath, playCount, lastPlayed}
TrackPlayCountChanged: "TrackPlayCountChanged",
// Autotag apply events — emitted while an async ApplyAsync job is in flight so the review UI can render per-folder progress
AutotagApplyStarted: "AutotagApplyStarted",
AutotagApplyProgress: "AutotagApplyProgress",