feat(queue): wire infinite play (auto-advance + immersive toggle)
When the queue runs out with InfiniteRadio autoplay on, build a smart artist radio seeded by the just-finished track and start it, so playback continues with related music and chains radio -> radio. The toggle, the AutoplayMode preference and the radio primitives already existed; only the trigger and the immersive button were missing. Wire the trigger at the auto-advance queue-end (naturally peer-gated) and enable the immersive infinity button (binds QueueState.infinite-play + toggle-infinite-play). Add QueueController::is_infinite_play(). Tauri appends the radio and retries next(); that would replay the old queue here because QueueManager::next() nulls current_index at the edge, so this starts the radio fresh via play_tracks to reach the same intended behavior. Manual-next refill is deferred (needs an explicit peer gate). cc
This commit is contained in:
3 files changed
+76
-2
No files matched your search
@@ -277,8 +277,8 @@ component ImmersivePlayerBar inherits Rectangle {
|
||||
x: 120px;
|
||||
y: 22px;
|
||||
icon: @image-url("../assets/icons/infinity.svg");
|
||||
active: false;
|
||||
enabled: false;
|
||||
active: QueueState.infinite-play;
|
||||
clicked => { QueueState.toggle-infinite-play(); }
|
||||
}
|
||||
|
||||
// Playback group: positioned from the play disc so play is exactly centered.
|
||||
|
||||
@@ -388,6 +388,59 @@ async fn advance_to_playable(
|
||||
}
|
||||
}
|
||||
|
||||
/// When the queue is exhausted and `InfiniteRadio` autoplay is on, build a
|
||||
/// smart artist radio seeded by the just-finished track and start it,
|
||||
/// replacing the spent queue. Returns `true` if a radio was started.
|
||||
///
|
||||
/// Tauri appends the radio then retries `next()`; that can't be ported 1:1
|
||||
/// because `QueueManager::next()` nulls `current_index` at the queue edge, so a
|
||||
/// retry replays the old queue from index 1 rather than the radio. Starting the
|
||||
/// radio fresh via `play_tracks` reaches Tauri's *intended* behavior and chains
|
||||
/// correctly — each radio's end re-seeds the next, giving true infinite play.
|
||||
async fn try_infinite_refill(
|
||||
runtime: &Runtime,
|
||||
weak: &slint::Weak<AppWindow>,
|
||||
seed_track_id: u64,
|
||||
) -> bool {
|
||||
let Some(controller) = QUEUE_CONTROLLER.get() else {
|
||||
return false;
|
||||
};
|
||||
if !controller.is_infinite_play() || seed_track_id == 0 {
|
||||
return false;
|
||||
}
|
||||
let artist_id = match runtime.core().get_track(seed_track_id).await {
|
||||
Ok(track) => match track.performer.as_ref().map(|p| p.id) {
|
||||
Some(id) => id,
|
||||
None => {
|
||||
log::warn!(
|
||||
"[qbz-slint] infinite radio: seed track {seed_track_id} has no performer"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
log::warn!("[qbz-slint] infinite radio: get_track {seed_track_id} failed: {e}");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
match runtime.core().create_smart_artist_radio(artist_id).await {
|
||||
// play_tracks replaces the spent queue and starts the radio; it already
|
||||
// drops blacklisted tracks, so its `false` means nothing playable.
|
||||
Ok(tracks) if !tracks.is_empty() => play_tracks(
|
||||
runtime.clone(),
|
||||
weak.clone(),
|
||||
tokio::runtime::Handle::current(),
|
||||
tracks,
|
||||
0,
|
||||
),
|
||||
Ok(_) => false,
|
||||
Err(e) => {
|
||||
log::warn!("[qbz-slint] infinite radio: build failed: {e}");
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Run the audible step for `track_id`: grab the Qobuz client and call
|
||||
/// the player's self-contained `play_track`. Errors are logged, not
|
||||
/// surfaced — the poll loop keeps the UI consistent regardless.
|
||||
@@ -3937,6 +3990,14 @@ pub fn start_poll_loop(
|
||||
// skipped (bounded — see `advance_to_playable`); exhaustion
|
||||
// lands in the queue-finished arm below.
|
||||
if track_ended {
|
||||
// Seed for InfiniteRadio: the track that just ended is still the
|
||||
// current one (advance hasn't moved the cursor yet).
|
||||
let ended_track_id = runtime
|
||||
.core()
|
||||
.current_track()
|
||||
.await
|
||||
.map(|t| t.id)
|
||||
.unwrap_or(0);
|
||||
last_track_id = 0;
|
||||
was_playing = false;
|
||||
seen_position = 0;
|
||||
@@ -3945,6 +4006,9 @@ pub fn start_poll_loop(
|
||||
let next_id = track.id;
|
||||
after_track_change(&runtime, &weak, next_id).await;
|
||||
refresh_sidebar(true);
|
||||
} else if try_infinite_refill(&runtime, &weak, ended_track_id).await {
|
||||
// InfiniteRadio started a fresh smart radio (play_tracks
|
||||
// replaced the queue and refreshes the sidebar itself).
|
||||
} else {
|
||||
log::info!("[qbz-slint] playback: queue finished");
|
||||
// Nothing more will play — force-clear any lingering spinner.
|
||||
|
||||
@@ -789,6 +789,16 @@ impl QueueController {
|
||||
});
|
||||
}
|
||||
|
||||
/// Whether `InfiniteRadio` autoplay is currently on (the queue auto-refills
|
||||
/// with a smart radio when it runs out). Reads the same playback preference
|
||||
/// the toggle and the sidebar flag use.
|
||||
pub fn is_infinite_play(&self) -> bool {
|
||||
self.playback
|
||||
.get_preferences()
|
||||
.map(|p| p.autoplay_mode == AutoplayMode::InfiniteRadio)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Open the Add-to-Playlist picker seeded with the queue's tracks
|
||||
/// (current + upcoming, de-duplicated, in play order). The picker's inline
|
||||
/// "Create new playlist" row turns the queue into a named playlist; picking
|
||||
|
||||
Reference in new issue
Block a user