mirror of
https://github.com/Boof2015/astra-mobile.git
synced 2026-08-20 04:30:54 +02:00
fix now playing source label
This commit is contained in:
@@ -147,6 +147,7 @@ export function installMobileSessionPersistence(
|
||||
state.tracks !== previous.tracks
|
||||
|| state.activeIndex !== previous.activeIndex
|
||||
|| state.hasSnapshot !== previous.hasSnapshot
|
||||
|| state.source !== previous.source
|
||||
) {
|
||||
scheduleDebouncedSave();
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ test('round trips a normalized versioned snapshot', () => {
|
||||
shuffle: true,
|
||||
repeat: 'all',
|
||||
originalOrderPaths: ['file:///b.flac', 'file:///a.flac'],
|
||||
source: { kind: 'playlist', label: 'Playlist 11' },
|
||||
},
|
||||
};
|
||||
|
||||
@@ -133,9 +134,37 @@ test('rejects unknown versions and safely defaults corrupt fields', () => {
|
||||
shuffle: false,
|
||||
repeat: 'none',
|
||||
originalOrderPaths: ['file:///a.flac', 'file:///b.flac'],
|
||||
source: null,
|
||||
});
|
||||
});
|
||||
|
||||
test('accepts legacy playback snapshots without a source and rejects malformed sources', () => {
|
||||
const legacy = normalizeMobileSessionSnapshot({
|
||||
kind: MOBILE_SESSION_KIND,
|
||||
schemaVersion: MOBILE_SESSION_SCHEMA_VERSION,
|
||||
savedAt: 123,
|
||||
lastStableHref: '/',
|
||||
playback: {
|
||||
queuePaths: ['file:///a.flac'],
|
||||
activeIndex: 0,
|
||||
position: 12,
|
||||
shuffle: false,
|
||||
repeat: 'none',
|
||||
originalOrderPaths: ['file:///a.flac'],
|
||||
},
|
||||
});
|
||||
assert.equal(legacy?.playback?.source, null);
|
||||
|
||||
const malformed = normalizeMobileSessionSnapshot({
|
||||
...legacy,
|
||||
playback: {
|
||||
...legacy?.playback,
|
||||
source: { kind: 'playlist', label: ' ' },
|
||||
},
|
||||
});
|
||||
assert.equal(malformed?.playback?.source, null);
|
||||
});
|
||||
|
||||
test('restores duplicates and clamps position to the current duration', () => {
|
||||
const resolved = resolvePlaybackSession(
|
||||
{
|
||||
@@ -164,11 +193,13 @@ test('chooses the next survivor when the active track disappeared, then the prev
|
||||
shuffle: false,
|
||||
repeat: 'none',
|
||||
originalOrderPaths: ['file:///a.flac', 'file:///missing.flac', 'file:///c.flac'],
|
||||
source: { kind: 'favorites', label: 'Favorites' },
|
||||
},
|
||||
tracks
|
||||
);
|
||||
assert.equal(next?.tracks[next.activeIndex].title, 'C');
|
||||
assert.equal(next?.position, 0);
|
||||
assert.deepEqual(next?.source, { kind: 'favorites', label: 'Favorites' });
|
||||
|
||||
const previous = resolvePlaybackSession(
|
||||
{
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { normalizePlaybackSource } from '../audio/playbackSource.ts';
|
||||
import type { PlaybackSource } from '../types/audio.ts';
|
||||
|
||||
export const MOBILE_SESSION_KIND = 'astra-mobile-session';
|
||||
export const MOBILE_SESSION_SCHEMA_VERSION = 1;
|
||||
|
||||
@@ -15,6 +18,8 @@ export interface PlaybackSessionSnapshotV1 {
|
||||
shuffle: boolean;
|
||||
repeat: SessionRepeatMode;
|
||||
originalOrderPaths: string[];
|
||||
/** Optional for backward compatibility with version-1 snapshots written before queue sources. */
|
||||
source?: PlaybackSource | null;
|
||||
}
|
||||
|
||||
export interface MobileSessionSnapshotV1 {
|
||||
@@ -37,6 +42,7 @@ export interface ResolvedPlaybackSession<T extends SessionTrackLike> {
|
||||
shuffle: boolean;
|
||||
repeat: SessionRepeatMode;
|
||||
originalOrderPaths: string[];
|
||||
source: PlaybackSource | null;
|
||||
}
|
||||
|
||||
export interface StableRouteValidationContext {
|
||||
@@ -280,6 +286,7 @@ export function normalizePlaybackSession(value: unknown): PlaybackSessionSnapsho
|
||||
shuffle: value.shuffle === true,
|
||||
repeat: normalizeRepeat(value.repeat),
|
||||
originalOrderPaths,
|
||||
source: normalizePlaybackSource(value.source),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -358,5 +365,6 @@ export function resolvePlaybackSession<T extends SessionTrackLike>(
|
||||
originalOrderPaths: samePathMultiset(originalOrderPaths, resolvedQueuePaths)
|
||||
? originalOrderPaths
|
||||
: resolvedQueuePaths,
|
||||
source: snapshot.source ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user