mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-21 23:05:46 +00:00
7a7a9f5e6b
111 of 122 top-level src/utils/ files move into 16 topic folders (audio, cache, cover, share, server, playback, playlist, deviceSync, waveform, mix, format, export, changelog, ui, perf, componentHelpers). True singletons with no cluster stay at the utils/ root. Pure file-move: a path-aware codemod rewrote 539 relative-import specifiers across 275 files; no logic touched. The hot-path coverage gate list (.github/frontend-hot-path-files.txt) is updated to the new paths for the 11 gated utils files — a mechanical consequence of the move, not a CI change. tsc is green.
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { invoke } from '@tauri-apps/api/core';
|
|
import { coerceWaveformBins } from '../utils/waveform/waveformParse';
|
|
import { usePlayerStore } from './playerStore';
|
|
import { getWaveformRefreshGen } from './waveformRefreshGen';
|
|
|
|
/** Subsonic-server waveform-cache row as Rust hands it back. */
|
|
export type WaveformCachePayload = {
|
|
/** May be `number[]` or `Uint8Array` depending on Tauri IPC / serde path. */
|
|
bins: number[] | Uint8Array;
|
|
binCount: number;
|
|
isPartial: boolean;
|
|
knownUntilSec: number;
|
|
durationSec: number;
|
|
updatedAt: number;
|
|
};
|
|
|
|
/**
|
|
* Fetch the cached waveform row for `trackId` from Rust and apply its bins
|
|
* to the player store — but only if (a) the refresh generation snapshot
|
|
* still matches (no newer invalidation has fired meanwhile) and (b) the
|
|
* track is still the current one. Best-effort: any failure leaves the
|
|
* seekbar with the placeholder waveform.
|
|
*/
|
|
export async function refreshWaveformForTrack(trackId: string): Promise<void> {
|
|
if (!trackId) return;
|
|
const gen = getWaveformRefreshGen(trackId);
|
|
try {
|
|
const row = await invoke<WaveformCachePayload | null>('analysis_get_waveform_for_track', { trackId });
|
|
if (getWaveformRefreshGen(trackId) !== gen) return;
|
|
// Never apply bins for a non-current track (e.g. gapless byte-preload fetches the neighbour).
|
|
if (usePlayerStore.getState().currentTrack?.id !== trackId) return;
|
|
const bins = row ? coerceWaveformBins(row.bins) : null;
|
|
if (!bins || bins.length === 0) {
|
|
usePlayerStore.setState({
|
|
waveformBins: null,
|
|
});
|
|
return;
|
|
}
|
|
usePlayerStore.setState({
|
|
waveformBins: bins,
|
|
});
|
|
} catch {
|
|
// best-effort; seekbar falls back to placeholder waveform
|
|
}
|
|
}
|