fix(player): persist player prefs outside quota-bound queue blob (#958)

* fix(player): persist volume/repeat in dedicated localStorage key

Player prefs were bundled with the full queue blob in psysonic-player; after
thin-state #872 a large queue can exceed the quota and safeStorage silently
drops every write, so volume and repeat mode stopped surviving restarts.
Move them to psysonic_player_prefs, gate main-blob writes until rehydrate,
and sync volume to the Rust engine on startup.

* fix(player): split queue visibility and Last.fm cache from main persist blob

Move isQueueVisible and lastfmLovedCache to dedicated localStorage keys so
they keep saving when psysonic-player hits the quota on large queues. Include
the new keys in settings backup export.

* docs: note player prefs persist fix in CHANGELOG and credits (PR #958)
This commit is contained in:
cucadmuh
2026-06-03 21:55:20 +03:00
committed by GitHub
parent 40932d28e2
commit 75e2c7f9c6
10 changed files with 334 additions and 10 deletions
+56
View File
@@ -0,0 +1,56 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import {
persistPlayerPrefs,
readInitialPlayerPrefs,
} from './playerPrefsStorage';
const PREFS_KEY = 'psysonic_player_prefs';
const LEGACY_KEY = 'psysonic-player';
beforeEach(() => {
window.localStorage.clear();
});
afterEach(() => {
window.localStorage.clear();
});
describe('readInitialPlayerPrefs', () => {
it('defaults when nothing is stored', () => {
expect(readInitialPlayerPrefs()).toEqual({ volume: 0.8, repeatMode: 'off' });
});
it('reads the dedicated prefs key', () => {
window.localStorage.setItem(PREFS_KEY, JSON.stringify({ volume: 0.42, repeatMode: 'all' }));
expect(readInitialPlayerPrefs()).toEqual({ volume: 0.42, repeatMode: 'all' });
});
it('clamps an out-of-range volume', () => {
window.localStorage.setItem(PREFS_KEY, JSON.stringify({ volume: 1.5, repeatMode: 'one' }));
expect(readInitialPlayerPrefs()).toEqual({ volume: 1, repeatMode: 'one' });
});
it('falls back to the legacy psysonic-player blob when the dedicated key is absent', () => {
window.localStorage.setItem(
LEGACY_KEY,
JSON.stringify({ state: { volume: 0.25, repeatMode: 'one', queueItems: [] } }),
);
expect(readInitialPlayerPrefs()).toEqual({ volume: 0.25, repeatMode: 'one' });
});
it('prefers the dedicated key over the legacy blob', () => {
window.localStorage.setItem(PREFS_KEY, JSON.stringify({ volume: 0.6, repeatMode: 'off' }));
window.localStorage.setItem(
LEGACY_KEY,
JSON.stringify({ state: { volume: 0.1, repeatMode: 'all' } }),
);
expect(readInitialPlayerPrefs()).toEqual({ volume: 0.6, repeatMode: 'off' });
});
});
describe('persistPlayerPrefs', () => {
it('round-trips through readInitialPlayerPrefs', () => {
persistPlayerPrefs({ volume: 0.33, repeatMode: 'all' });
expect(readInitialPlayerPrefs()).toEqual({ volume: 0.33, repeatMode: 'all' });
});
});