mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-21 23:05:46 +00:00
refactor(player): E.18 — extract three transport-coordination modules (#581)
Cluster of three small thematically-related cuts in one PR (per the new
'cluster, don't single-shot' convention):
- `src/store/seekTargetState.ts` — the seek-target guard (`seekTarget`,
`seekTargetSetAt`, `SEEK_TARGET_GUARD_TIMEOUT_MS`, set/clear/get
accessors) that suppresses stale Rust progress ticks until the
engine catches up to the requested position
- `src/store/togglePlayLock.ts` — the 300 ms double-click cooldown
behind a `tryAcquireTogglePlayLock()` helper that auto-releases on
a timer (collapses the three-line inline pattern in `togglePlay`)
- `src/store/loudnessReseed.ts` — the full `reseedLoudnessForTrackId`
pipeline (gen-bump → cache + backfill wipe → state reset → server
row delete → forced seed enqueue), pulled out of playerStore as a
single async helper
All three were file-private; no caller-side changes outside
playerStore's own imports. The progress handler's seek-guard branch is
now ~3 lines shorter and reads through accessors. `togglePlay` collapses
to one guard check.
24 tests across the three modules pin the API contracts.
playerStore 3189 → 3139 LOC.
This commit is contained in:
committed by
GitHub
parent
9029ab8ec5
commit
4c64844349
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Tracks the target time of the most recent user seek. The progress
|
||||
* handler reads this to suppress stale Rust progress ticks until the
|
||||
* engine has actually caught up to the new position — without the guard,
|
||||
* the slider snaps back briefly because Rust keeps emitting the old
|
||||
* position until the seek finishes propagating.
|
||||
*
|
||||
* Lifetime: set when a seek IPC is issued, cleared once progress reaches
|
||||
* within ~2 s of the target or when the guard timeout (5 s) elapses.
|
||||
*/
|
||||
|
||||
export const SEEK_TARGET_GUARD_TIMEOUT_MS = 5000;
|
||||
|
||||
let seekTarget: number | null = null;
|
||||
let seekTargetSetAt = 0;
|
||||
|
||||
export function setSeekTarget(seconds: number): void {
|
||||
seekTarget = seconds;
|
||||
seekTargetSetAt = Date.now();
|
||||
}
|
||||
|
||||
export function clearSeekTarget(): void {
|
||||
seekTarget = null;
|
||||
seekTargetSetAt = 0;
|
||||
}
|
||||
|
||||
export function getSeekTarget(): number | null {
|
||||
return seekTarget;
|
||||
}
|
||||
|
||||
export function getSeekTargetSetAt(): number {
|
||||
return seekTargetSetAt;
|
||||
}
|
||||
|
||||
/** Test-only: reset both mutables so each spec starts fresh. */
|
||||
export function _resetSeekTargetStateForTest(): void {
|
||||
seekTarget = null;
|
||||
seekTargetSetAt = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user