mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
cb1a110afb
Relocate the playback/queue/transport/audio-output engine out of the type-first
store/ + utils/playback/ + utils/audio/ dirs into a cohesive src/features/playback/,
structure-preserving:
store/<x> -> features/playback/store/<x>
store/audioListenerSetup/<x> -> features/playback/store/audioListenerSetup/<x>
utils/playback/<x> -> features/playback/utils/playback/<x>
utils/audio/<x> -> features/playback/utils/audio/<x>
184 files moved (107 source + 77 tests), 365 consumers rewritten. Pure move — no
behavior change, no state-split (the playerStore state-split stays a separate M5
question). Enabled by this session's decouple seams (artist/offline/orbit/auth →
core registries), so the engine carries no inbound core->feature inversion: store/
now holds only the 50 cross-cutting global stores (auth family, the seams, library
index, UI/settings stores).
KEPT OUT of the move (would re-create global->engine edges): the 3 pure config
helpers utils/audio/{loudnessPreAnalysisSlider,hiResCrossfadeResample} +
utils/playback/autodjOverlapCap (authStore + settings UI read them — they stay in
utils/). Ambiguous view-state stores (eqStore, queueToolbarStore,
playerBarLayoutStore) stay global (no engine imports).
Consumers use DEEP paths (@/features/playback/...), no barrel — matches the lib/
approach and avoids barrel-mock-collapse across the 140 usePlayerStore consumers.
Two tolerated type-only core->feature edges remain (localPlaybackStore->QueueItemRef,
localPlaybackMigration->HotCacheEntry, both erased).
tsc 0, lint 0, full suite 319/2353 green, iron-rule clean (no runtime store->feature
import). Behavior-touching only via the prerequisite bridge seam (already QA-flagged);
the move itself is pure.
104 lines
3.1 KiB
TypeScript
104 lines
3.1 KiB
TypeScript
import {
|
|
persistQueueVisibility,
|
|
} from '@/features/playback/store/queueVisibilityStorage';
|
|
import type { PlayerState } from '@/features/playback/store/playerStoreTypes';
|
|
import {
|
|
ensurePlaybackServerActive,
|
|
playbackServerDiffersFromActive,
|
|
} from '@/features/playback/utils/playback/playbackServer';
|
|
|
|
type SetState = (
|
|
partial: Partial<PlayerState> | ((state: PlayerState) => Partial<PlayerState>),
|
|
) => void;
|
|
|
|
/**
|
|
* Pure-UI state setters: no audio engine / network side effects.
|
|
* Add new actions here only if they fit that contract.
|
|
*/
|
|
export function createUiStateActions(set: SetState): Pick<
|
|
PlayerState,
|
|
| 'setStarredOverride'
|
|
| 'setUserRatingOverride'
|
|
| 'openContextMenu'
|
|
| 'closeContextMenu'
|
|
| 'openSongInfo'
|
|
| 'closeSongInfo'
|
|
| 'toggleQueue'
|
|
| 'setQueueVisible'
|
|
| 'toggleFullscreen'
|
|
| 'toggleRepeat'
|
|
> {
|
|
return {
|
|
setStarredOverride: (id, starred) =>
|
|
set(s => ({ starredOverrides: { ...s.starredOverrides, [id]: starred } })),
|
|
|
|
setUserRatingOverride: (id, rating) =>
|
|
set(s => {
|
|
const nextOverrides = { ...s.userRatingOverrides };
|
|
if (rating === 0) delete nextOverrides[id];
|
|
else nextOverrides[id] = rating;
|
|
// Thin-state: the queue's copy lives in the resolver cache; the override
|
|
// map (merged on read via applyQueueOverrides) drives the queue-row UI.
|
|
return {
|
|
userRatingOverrides: nextOverrides,
|
|
currentTrack:
|
|
s.currentTrack?.id === id ? { ...s.currentTrack, userRating: rating } : s.currentTrack,
|
|
};
|
|
}),
|
|
|
|
openContextMenu: (x, y, item, type, queueIndex, playlistId, playlistSongIndex, shareKindOverride, pinToPlaybackServer) => {
|
|
const pin = pinToPlaybackServer ?? type === 'queue-item';
|
|
const open = () =>
|
|
set({
|
|
contextMenu: {
|
|
isOpen: true,
|
|
x,
|
|
y,
|
|
item,
|
|
type,
|
|
queueIndex,
|
|
playlistId,
|
|
playlistSongIndex,
|
|
shareKindOverride,
|
|
pinToPlaybackServer: pin,
|
|
},
|
|
});
|
|
if (pin && playbackServerDiffersFromActive()) {
|
|
void ensurePlaybackServerActive().then(ok => {
|
|
if (ok) open();
|
|
});
|
|
return;
|
|
}
|
|
open();
|
|
},
|
|
|
|
closeContextMenu: () =>
|
|
set(state => ({
|
|
contextMenu: { ...state.contextMenu, isOpen: false },
|
|
})),
|
|
|
|
openSongInfo: (songId) => set({ songInfoModal: { isOpen: true, songId } }),
|
|
closeSongInfo: () => set({ songInfoModal: { isOpen: false, songId: null } }),
|
|
|
|
toggleQueue: () =>
|
|
set(state => {
|
|
const next = !state.isQueueVisible;
|
|
persistQueueVisibility(next);
|
|
return { isQueueVisible: next };
|
|
}),
|
|
|
|
setQueueVisible: (v: boolean) => {
|
|
persistQueueVisibility(v);
|
|
set({ isQueueVisible: v });
|
|
},
|
|
|
|
toggleFullscreen: () => set(state => ({ isFullscreenOpen: !state.isFullscreenOpen })),
|
|
|
|
toggleRepeat: () =>
|
|
set(state => {
|
|
const modes = ['off', 'all', 'one'] as const;
|
|
return { repeatMode: modes[(modes.indexOf(state.repeatMode) + 1) % modes.length] };
|
|
}),
|
|
};
|
|
}
|