From 07d5d95cea305d5cc931e9247d519745bb4a6dfb Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Fri, 20 Feb 2026 19:58:54 -0600 Subject: [PATCH] feat(session): extend frontend service and add restoreView helpers Update PersistedSession interface with last_view fields. Add lastView, viewContextId, viewContextType params to saveSessionState(). Add restoreView(), setRestoredPlaylistId(), setRestoredLocalAlbumId() to navigationStore for session restore without triggering data fetches. --- src/lib/services/sessionService.ts | 11 ++++++++++- src/lib/stores/navigationStore.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/lib/services/sessionService.ts b/src/lib/services/sessionService.ts index 01a349f2b..c42fe467f 100644 --- a/src/lib/services/sessionService.ts +++ b/src/lib/services/sessionService.ts @@ -31,6 +31,9 @@ export interface PersistedSession { repeat_mode: string; // "off" | "all" | "one" was_playing: boolean; saved_at: number; + last_view: string; + view_context_id: string | null; + view_context_type: string | null; } /** @@ -43,7 +46,10 @@ export async function saveSessionState( volume: number, shuffleEnabled: boolean, repeatMode: string, - wasPlaying: boolean + wasPlaying: boolean, + lastView?: string, + viewContextId?: string | null, + viewContextType?: string | null ): Promise { try { await invoke('v2_save_session_state', { @@ -54,6 +60,9 @@ export async function saveSessionState( shuffleEnabled, repeatMode, wasPlaying, + lastView: lastView ?? 'home', + viewContextId: viewContextId ?? null, + viewContextType: viewContextType ?? null, }); console.log('[Session] State saved successfully'); } catch (err) { diff --git a/src/lib/stores/navigationStore.ts b/src/lib/stores/navigationStore.ts index 520fa1ba4..05c3420d3 100644 --- a/src/lib/stores/navigationStore.ts +++ b/src/lib/stores/navigationStore.ts @@ -237,6 +237,36 @@ export function navigateToFavorites(tab?: FavoritesTab): void { navigateTo(favoritesViewForTab(targetTab)); } +// ============ Session Restore ============ + +/** + * Restore a view as initial state (Home always in history root). + * Used during session restore to set the view without triggering data fetches. + */ +export function restoreView(view: ViewType): void { + activeView = view; + viewHistory = ['home']; + if (view !== 'home') { + viewHistory.push(view); + } + forwardHistory = []; + notifyListeners(); +} + +/** + * Set playlist ID without triggering navigation (for session restore). + */ +export function setRestoredPlaylistId(playlistId: number): void { + selectedPlaylistId = playlistId; +} + +/** + * Set local album ID without triggering navigation (for session restore). + */ +export function setRestoredLocalAlbumId(albumId: string): void { + selectedLocalAlbumId = albumId; +} + // ============ Scroll Position ============ /**