[Refactor] Move playtime tracking to a dedicated Zustand store in the Frontend, and a dedicated class in the Backend #5034
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements the changes I've mentioned here: #5014 (review)
The Frontend now uses a Zustand store to house playtime information. If the playtime changes, the Backend sends updates to it & the Frontend just re-renders automatically
Playtime tracking in the Backend is done automatically with a new
playSessionEndedevent, emitted at the end oflaunchCallback. A newPlaytimeManagerclass listens to this event and updates playtime accordingly. The GOG library manager also listens to this event to sync the playtime with GOGIn the process, I've made some housekeeping changes:
${string}_${Runner}, to avoid game ID collisionsIntl.DateTimeFormat(it used the system locale before, which may not be the locale the user configured)Intl.DurationFormatto present the duration in a more friendly format, and now includes secondsDurationFormatfor this, since it's not in TypeScript yet (for some reason)TODO:
LibraryManagertypeNotes:
gameStatusUpdateevent instead, but it seems we currently emit thedonestatus multiple times. Cleaning that up may cause side-effects, so I left it alone for nowUse the following Checklist if you have changed something on the Backend or Frontend: