mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
refactor(player): E.28 — extract storage + hotkey helpers cluster (#592)
Two small file-private bits move out of playerStore.ts:
- `src/store/queueVisibilityStorage.ts` — `readInitialQueueVisibility`
and `persistQueueVisibility` (the QueuePanel show/hide toggle
survives reloads via a localStorage round-trip; SSR / private-mode
failures swallowed silently).
- `src/store/queueUndoHotkey.ts` — `installQueueUndoHotkey` (Ctrl+Z /
Cmd+Z queue undo, Ctrl+Shift+Z redo, document-capture; skips text
fields so native text undo stays; idempotent via window-scoped
flag; mini-player window skipped). Added a `_resetQueueUndoHotkeyForTest`
that removes the keydown listener too (needed so vitest specs
don't accumulate handlers across tests).
playerStore re-exports `installQueueUndoHotkey` so bootstrap + tests
keep their existing `from './playerStore'` imports. The
queue-visibility helpers were file-private; no re-exports.
Side-cleanup: `getWindowKind` import is gone from playerStore (only
the moved hotkey installer used it).
16 focused tests pin the storage round-trip, the idempotency flag, the
modifier + key matching, the editable-target skip, and the
preventDefault contract.
playerStore 1940 → 1879 LOC.
This commit is contained in:
committed by
GitHub
parent
013d6144ca
commit
b0418bf920
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Persists the QueuePanel visibility toggle to localStorage so it
|
||||
* survives reloads. Defaults to true on the first run (no stored value)
|
||||
* and on SSR / non-DOM contexts (`typeof window === 'undefined'`).
|
||||
*
|
||||
* Storage failures (quota, private-mode) are silently ignored — the UI
|
||||
* keeps the in-memory state and the user just loses the persisted
|
||||
* preference after the next restart.
|
||||
*/
|
||||
|
||||
const QUEUE_VISIBILITY_STORAGE_KEY = 'psysonic_queue_visible';
|
||||
|
||||
export function readInitialQueueVisibility(): boolean {
|
||||
if (typeof window === 'undefined') return true;
|
||||
try {
|
||||
const raw = window.localStorage.getItem(QUEUE_VISIBILITY_STORAGE_KEY);
|
||||
if (raw === 'true') return true;
|
||||
if (raw === 'false') return false;
|
||||
} catch {
|
||||
// ignore storage access failures and fall back to default
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function persistQueueVisibility(visible: boolean): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
try {
|
||||
window.localStorage.setItem(QUEUE_VISIBILITY_STORAGE_KEY, String(visible));
|
||||
} catch {
|
||||
// ignore storage access failures
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user