From 0995aaa8af0ba486571b38450979e2eb14bc86d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Padez?= Date: Mon, 27 Jul 2026 12:24:47 +0000 Subject: [PATCH] music (web): resume currently-playing on reload/return MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The web player kept no durable state, so a reload (and a return to /music, whose cwd resets) lost your place. Wire it to the platform's per-user /api/music/now-playing (same endpoints the app uses): - MusicPlayerHost persists a snapshot (track + position) on play/pause + track change + a 10s heartbeat (position read via ref so the heartbeat stays live). - On first load with an empty queue it restores that snapshot: rebuilds the album queue (sortTracks), loads it PAUSED (browsers block autoplay on reload), and seeks to the saved position once metadata is in. A restore guard stops the load from clobbering the saved position with 0. - MusicDetail auto-opens the currently-playing album once on mount (when it has no location yet), so /music lands on the track — without yanking you back after you navigate away. Adds loadQueue() (paused) to useMusicPlayer + a NowPlaying type. tsgo clean. Co-Authored-By: Claude Opus 4.8 --- .../src/MusicPlayer/MusicPlayerHost.tsx | 82 +++++++++++++++++-- .../src/MusicPlayer/useMusicPlayer.ts | 6 +- .../officerdev/src/apps/Music/MusicDetail.tsx | 18 +++- .../officerdev/src/apps/Music/shared.ts | 12 +++ 4 files changed, 110 insertions(+), 8 deletions(-) diff --git a/src/workspaces/officerdev/src/MusicPlayer/MusicPlayerHost.tsx b/src/workspaces/officerdev/src/MusicPlayer/MusicPlayerHost.tsx index 96190a80..a507360e 100644 --- a/src/workspaces/officerdev/src/MusicPlayer/MusicPlayerHost.tsx +++ b/src/workspaces/officerdev/src/MusicPlayer/MusicPlayerHost.tsx @@ -3,7 +3,7 @@ import { useClient } from 'hooks/useClient'; import { Play, Pause, SkipBack, SkipForward, X, Volume2, VolumeX } from 'lucide-react'; import { useSeekBar, SeekBar } from '../apps/FileViewer/renderers/SeekBar'; import { MusicHeart } from '../apps/Music/MusicHeart'; -import { trackHomePath } from '../apps/Music/shared'; +import { sortTracks, trackHomePath, type AlbumMeta, type NowPlaying } from '../apps/Music/shared'; import { useMusicPlayer, type PlayerTrack } from './useMusicPlayer'; // Mounted once in the persistent DashboardLayout (outside ), so it owns the single