feat(purchases): wire play routing + now-playing active-track (Slint)

Slice 10/13. A.2: per-track row play in both purchases views routes to
playback::play_track_now (single track, NO replacePlaybackQueue/setPlaybackContext)
instead of media_action play_track_in_context. A.1: Play-album confirmed on the
regular album fetch+queue path. New mirror_now_playing_to_purchases feeds both
purchases globals' active-track-id + playback-active from the now-playing refresh
(meta apply + poll tick). Folded Slice-9 review fixes: detail + list track titles
trimmed (formatTrackTitle parity), dead PurchaseDetailState.artwork-url removed.
Fixed E0308 (track_id u64). Front-end type-check clean (zero diagnostics).

cc
This commit is contained in:
vicrodh committed 2026-06-24 16:14:41 -06:00
1 parent be87fe3377
commit 18827eaab4
4 files changed
+82 -17

No files matched your search

+42 -12
View File
@@ -11121,13 +11121,25 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
});
}
{
// play-track — single-track play with NO queue mutation (Slice 10
// finalizes the routing; here it goes through the standard media-action
// path emitted by the view).
// play-track — per-track row play (§A.2): plays the SINGLE clicked track
// with NO surrounding album queue and NO playback-context seeding —
// asymmetric with Play-album (§A.1, which DOES build a full queue). This
// does NOT route through `media_action("track", …, "play")` /
// `play_track_in_context` (which would build a queue from the visible
// tracklist); it goes straight to the single-track primitive
// `play_track_now`, which streams the catalog track (NOT the downloaded
// file). Mirrors Svelte `handleDisplayTrackPlay` (+page.svelte:4016-4045).
let runtime = app_runtime.clone();
let weak = window.as_weak();
let handle = tokio_rt.handle().clone();
window.global::<PurchasesActions>().on_play_track(move |id| {
let Some(w) = weak.upgrade() else { return };
w.invoke_media_action("track".into(), id, "play".into());
let Ok(track_id) = id.parse::<u64>() else { return };
playback::play_track_now(
runtime.clone(),
weak.clone(),
handle.clone(),
track_id,
);
});
}
{
@@ -11307,9 +11319,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
});
}
{
// play-album — Play-album routing (Slice 10 finalizes A.1; here it goes
// through the standard album-play media-action emitted by the shell, NOT
// a purchase command, NOT the downloaded file).
// play-album — Play-album routing (§A.1): plays via the REGULAR album
// path, NOT a purchase command and NOT the downloaded local file. The
// standard `media_action("album", id, "play")` arm routes a Qobuz album
// id (a purchase album id is always numeric, never a local key) to
// `playback::play_album`, which fetches the album through the regular
// `get_album` core call, builds the FULL backend queue, replaces it at
// index 0, and starts track 0 — the SAME path every other album surface
// uses. Mirrors Svelte `playAlbumById` (+page.svelte:2404-2450, which
// calls the 12th `v2_get_album` command + replacePlaybackQueue + playTrack).
let weak = window.as_weak();
window.global::<PurchaseDetailActions>().on_play_album(move || {
let Some(w) = weak.upgrade() else { return };
@@ -11321,14 +11339,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
});
}
{
// play-track(id) — per-track single-track play (Slice 10 finalizes A.2;
// standard media-action path, no queue mutation).
// play-track(id) — per-track single-track play (§A.2): SINGLE track, NO
// album queue, NO playback-context seeding (asymmetric with Play-album,
// §A.1). Routes straight to `play_track_now` (single-track primitive,
// streams the catalog track — NOT the downloaded file), NOT through
// `media_action("track", …, "play")` / `play_track_in_context` (which
// would build a queue from the visible tracklist). Mirrors Svelte
// `handleDisplayTrackPlay` (+page.svelte:4016-4045).
let runtime = app_runtime.clone();
let weak = window.as_weak();
let handle = tokio_rt.handle().clone();
window
.global::<PurchaseDetailActions>()
.on_play_track(move |id| {
let Some(w) = weak.upgrade() else { return };
w.invoke_media_action("track".into(), id, "play".into());
let Ok(track_id) = id.parse::<u64>() else { return };
playback::play_track_now(
runtime.clone(),
weak.clone(),
handle.clone(),
track_id,
);
});
}
{
+35 -1
View File
@@ -22,7 +22,8 @@ use crate::adapter::SlintAdapter;
use crate::queue::QueueController;
use crate::{
AlbumState, AppWindow, ArtistState, ContentView, FavoritesState, ImmersiveState, LabelState,
NavState, NowPlayingState, PlaylistState, SearchState, TrackItem,
NavState, NowPlayingState, PlaylistState, PurchaseDetailState, PurchasesState, SearchState,
TrackItem,
};
/// The Queue sidebar controller, published once the shell is up so the
@@ -1375,6 +1376,7 @@ pub(crate) async fn refresh_now_playing_meta(runtime: &Runtime, weak: &slint::We
let album = track.album.clone();
let album_id = track.album_id.clone().unwrap_or_default();
let artist_id = track.artist_id.map(|id| id.to_string()).unwrap_or_default();
let track_id_num = track.id;
let track_id = track.id.to_string();
// Ephemeral tracks have no DB row → metadata-bound actions (favorite,
// add-to-playlist, track-info) are gated off in the UI via this flag.
@@ -1553,6 +1555,9 @@ pub(crate) async fn refresh_now_playing_meta(runtime: &Runtime, weak: &slint::We
np.set_album_id(album_id.into());
np.set_artist_id(artist_id.into());
np.set_track_id(track_id.into());
// Mirror the active track + playing flag onto the Purchases globals so a
// purchase track-row highlights/animates when it is the now-playing one.
mirror_now_playing_to_purchases(&w, track_id_num, true);
np.set_is_ephemeral(is_ephemeral);
np.set_source(source.into());
np.set_quality_tier(quality_tier.into());
@@ -1583,6 +1588,30 @@ pub(crate) async fn refresh_now_playing_meta(runtime: &Runtime, weak: &slint::We
load_now_playing_artwork_large(weak.clone(), preview_artwork);
}
/// Mirror the now-playing track id + active flag onto the two Purchases globals
/// (`PurchasesState` + `PurchaseDetailState`), which drive the purchase
/// track-row highlight (`active`) and the playing-bars (`playing`). Unlike the
/// album/favorites views (which bind directly to `NowPlayingState`), the
/// Purchases views were built with their own `active-track-id` / `playback-active`
/// `in` properties, so Rust must push the values. Matches Svelte, where both
/// views receive `activeTrackId={currentTrack?.id}` + `isPlaybackActive={isPlaying}`
/// (+page.svelte:6970-6984). Event-loop only (`w` is already upgraded).
fn mirror_now_playing_to_purchases(w: &AppWindow, track_id: u64, is_playing: bool) {
// active-track-id is compared against the row's string id; 0 → "" (no row
// highlighted), matching the Svelte `null` active id.
let id_str: slint::SharedString = if track_id == 0 {
slint::SharedString::new()
} else {
track_id.to_string().into()
};
let purchases = w.global::<PurchasesState>();
purchases.set_active_track_id(id_str.clone());
purchases.set_playback_active(is_playing);
let detail = w.global::<PurchaseDetailState>();
detail.set_active_track_id(id_str);
detail.set_playback_active(is_playing);
}
/// Record the playback CONTEXT — the source the queue was launched from — on
/// `NowPlayingState`, so the song-card layers button can navigate back to it.
/// Set once at play time; `refresh_now_playing_meta` leaves it untouched so it
@@ -3753,6 +3782,11 @@ pub fn start_poll_loop(
np.set_remaining(remaining.into());
np.set_playing(is_playing);
np.set_volume(volume.clamp(0.0, 1.0));
// Keep the Purchases globals in step with play/pause + the live
// track id every tick (the meta-apply seeds them on a track
// change; this follows pause/resume + the engine's own id flips).
// track_id 0 (idle) → "" active id (no row highlighted).
mirror_now_playing_to_purchases(&w, track_id, is_playing);
// REQ-1 fan-out: mirror to the miniplayer window (no-op when
// the mini is closed). Single tick, no second poll loop.
crate::miniplayer::mirror_tick(&w);
+5 -3
View File
@@ -1655,8 +1655,8 @@ fn track_item(t: &PurchaseTrack) -> PurchaseTrackItem {
};
PurchaseTrackItem {
id: t.id.to_string().into(),
// Purchased tracks have NO version field → formatTrackTitle == title.
title: t.title.clone().into(),
// Purchased tracks have NO version field → formatTrackTitle == title.trim().
title: t.title.trim().into(),
artist: t.performer.name.clone().into(),
artist_id: if t.performer.id != 0 {
t.performer.id.to_string().into()
@@ -2486,7 +2486,9 @@ fn build_detail_rows(
id: t.id.to_string().into(),
track_number: t.track_number as i32,
// Purchased tracks have NO version → formatTrackTitle == title.
title: t.title.clone().into(),
// `formatTrackTitle` trims the title (utils/trackTitle.ts), so trim
// here too for 1:1 parity.
title: t.title.trim().into(),
performer: t.performer.name.clone().into(),
show_performer,
duration: format_duration(t.duration).into(),
-1
View File
@@ -4492,7 +4492,6 @@ export global PurchaseDetailState {
in property <string> title: "";
in property <string> artist: "";
in property <string> artist-id: ""; // "" → artist is plain text (no link)
in property <string> artwork-url: "";
in property <image> artwork;
in property <bool> downloadable: true; // !downloadable → header overlay + no actions
in property <string> purchased-on: ""; // LONG-month "November 6, 2025" ("" hides)