mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 15:25:46 +00:00
refactor(utils): group utils/ files into topic folders (Phase L, part 1) (#689)
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.
This commit is contained in:
committed by
GitHub
parent
2409a1fec8
commit
7a7a9f5e6b
@@ -0,0 +1,61 @@
|
||||
import type { SubsonicSong } from '../../api/subsonicTypes';
|
||||
import { songToTrack } from './songToTrack';
|
||||
import { usePlayerStore } from '../../store/playerStore';
|
||||
function fadeOut(setVolume: (v: number) => void, from: number, durationMs: number): Promise<void> {
|
||||
return new Promise(resolve => {
|
||||
const steps = 16;
|
||||
const stepMs = durationMs / steps;
|
||||
let step = 0;
|
||||
const id = setInterval(() => {
|
||||
step++;
|
||||
setVolume(Math.max(0, from * (1 - step / steps)));
|
||||
if (step >= steps) {
|
||||
clearInterval(id);
|
||||
resolve();
|
||||
}
|
||||
}, stepMs);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Play a single song. When `queue` is provided, surrounds the chosen song with that queue
|
||||
* so Next/Prev work — pass the rail / pool the click came from. Mirrors playAlbum's fade-out.
|
||||
*/
|
||||
export async function playSongNow(song: SubsonicSong, queue?: SubsonicSong[]): Promise<void> {
|
||||
const track = songToTrack(song);
|
||||
const tracks = queue && queue.length > 0
|
||||
? queue.map(songToTrack)
|
||||
: [track];
|
||||
|
||||
const store = usePlayerStore.getState();
|
||||
const { isPlaying, volume } = store;
|
||||
|
||||
if (isPlaying) {
|
||||
await fadeOut(store.setVolume, volume, 700);
|
||||
usePlayerStore.setState({ volume });
|
||||
}
|
||||
|
||||
usePlayerStore.getState().playTrack(track, tracks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the song to the existing queue (if not already there) and immediately jump to it.
|
||||
* Existing queue stays intact — different from playSongNow which replaces the queue.
|
||||
*/
|
||||
export async function enqueueAndPlay(song: SubsonicSong): Promise<void> {
|
||||
const track = songToTrack(song);
|
||||
const store = usePlayerStore.getState();
|
||||
const { isPlaying, volume, queue } = store;
|
||||
|
||||
if (isPlaying) {
|
||||
await fadeOut(store.setVolume, volume, 700);
|
||||
usePlayerStore.setState({ volume });
|
||||
}
|
||||
|
||||
if (!queue.some(t => t.id === track.id)) {
|
||||
usePlayerStore.getState().enqueue([track]);
|
||||
}
|
||||
// playTrack with no queue arg uses the current state.queue, finds the track by id,
|
||||
// and sets queueIndex accordingly.
|
||||
usePlayerStore.getState().playTrack(track);
|
||||
}
|
||||
Reference in New Issue
Block a user