persistence

This commit is contained in:
Boof2015
2026-07-13 15:09:59 -04:00
parent 971dea8d53
commit 4e98bd5b8e
13 changed files with 1200 additions and 30 deletions
+6
View File
@@ -25,6 +25,8 @@ interface PlayerStore {
// Field names mirror desktop playerStore so queue/transport logic stays consistent.
shuffle: boolean;
repeat: RepeatMode;
/** Restored JS queue exists but has not been loaded into RNTP yet. */
restoredSessionPending: boolean;
setCurrentTrack: (track: Track | null) => void;
setPlaybackState: (state: PlaybackState) => void;
@@ -35,6 +37,7 @@ interface PlayerStore {
setMuted: (isMuted: boolean) => void;
setShuffle: (shuffle: boolean) => void;
setRepeat: (repeat: RepeatMode) => void;
setRestoredSessionPending: (pending: boolean) => void;
reset: () => void;
}
@@ -48,6 +51,7 @@ export const usePlayerStore = create<PlayerStore>((set) => ({
isMuted: false,
shuffle: false,
repeat: 'none',
restoredSessionPending: false,
setCurrentTrack: (currentTrack) => set({ currentTrack }),
setPlaybackState: (playbackState) => set({ playbackState }),
@@ -58,6 +62,7 @@ export const usePlayerStore = create<PlayerStore>((set) => ({
setMuted: (isMuted) => set({ isMuted }),
setShuffle: (shuffle) => set({ shuffle }),
setRepeat: (repeat) => set({ repeat }),
setRestoredSessionPending: (restoredSessionPending) => set({ restoredSessionPending }),
reset: () =>
set({
currentTrack: null,
@@ -65,5 +70,6 @@ export const usePlayerStore = create<PlayerStore>((set) => ({
currentTime: 0,
duration: 0,
pendingSeek: null,
restoredSessionPending: false,
}),
}));
+21 -11
View File
@@ -127,23 +127,33 @@ interface RemoteSourcesStore {
syncAll: () => Promise<void>;
}
let initPromise: Promise<void> | null = null;
export const useRemoteSourcesStore = create<RemoteSourcesStore>((set, get) => ({
sources: [],
initialized: false,
progressById: {},
init: async () => {
if (get().initialized) return;
const db = await openLibraryDb();
const sources = await getRemoteSources(db);
// Populate the URL registry from cached config/token (no network on launch).
await Promise.all(sources.filter((s) => s.enabled).map((s) => hydrateRegistry(s)));
set({ sources, initialized: true });
// The library's initial refresh may have run before the registry was hydrated,
// leaving remote artwork URLs unresolved — refresh once more now that it's ready.
if (sources.length > 0) {
await useLibraryStore.getState().refresh();
init: () => {
if (get().initialized) return Promise.resolve();
if (!initPromise) {
initPromise = (async () => {
const db = await openLibraryDb();
const sources = await getRemoteSources(db);
// Populate the URL registry from cached config/token (no network on launch).
await Promise.all(sources.filter((s) => s.enabled).map((s) => hydrateRegistry(s)));
set({ sources, initialized: true });
// The library's initial refresh may have run before the registry was hydrated,
// leaving remote artwork URLs unresolved — refresh once more now that it's ready.
if (sources.length > 0) {
await useLibraryStore.getState().refresh();
}
})().catch((error) => {
initPromise = null;
throw error;
});
}
return initPromise;
},
refresh: async () => {