The release-section "Load more" fetched a page and appended it to a structure
no view ever re-read. The handler pushed IN PLACE into the object behind
`readonly property var artist: JSON.parse(QbzArtist.artistJson)`, and the
releaseSections projection returned that same array on the unfiltered arm, so
both Repeaters were re-handed the identical reference and nothing was dirty.
The tree's own rule, written in cards/PlaylistCollage.qml: rebind requires a
NEW object reference. A second bug sat on the same path - the artist document
republishes progressively (stories, then each MusicBrainz section as it
resolves) and every republish re-runs the parse, wiping anything appended, so
fixing only the first would have left a bug that looks random. Both
pre-existing; the in-flight placeholder added earlier is what made an
always-silent no-op visible.
Appended pages now live in an overlay keyed by release type. It survives a
republish, emits new arrays so the Repeaters rebuild, dedupes by album id,
carries the reference's 4-page cap per bucket (artist.rs:718-720, which hands
off to the discography page beyond it), and is guarded against a page
requested on one artist landing on another's grid - releaseSectionReady
carries no artist id and every artist has an "album" bucket.
"See discography" was a pointer-cursor MouseArea with no onClicked under a
POC-NOTE saying the page was out of scope. ArtistReleasesView.qml +
artist_releases_qt.rs port ArtistReleasesView.slint: infinite scroll rather
than a button, plus the loading, error-with-retry, empty and offline arms.
The album page's "More from <artist>" view-all is a second door to the same
page. Its paging offset counts what the SERVER returned rather than the
rendered row count the reference uses: blacklist filtering and id dedupe make
the rendered count smaller, so the reference re-requests seen rows and skips
the tail whenever the blacklist is non-empty.
The per-section sort was a dimmed Rectangle with no MouseArea, under a
comment asserting no seam existed. It is now a real QbzSelect with the
reference's five options and index mapping, persisted per release type in
artist_prefs. Choosing "Default" after a sort does not restore the server
order until the page reloads - that is the reference's behaviour
(album_map.rs:262 is a bare no-op arm and resort sorts the live model), kept
deliberately rather than diverged.
Also, two visual fixes from the same round that share these files: Popular
Tracks drew its cover at radius 8 where the shared rows/TrackRow.qml uses 4,
and the album page's rail mounts said `width: parent.width` inside a Column
with 32px padding - QML padding shifts children without narrowing
parent.width, so the rails hung 32px off the right and the right page chevron
landed outside the window.
Carries scripts/qt-diag.sh, which has been sitting untracked since the
rendering round: it answers "which backend is this actually running on" from
a real graphical session, refusing ssh and refusing offscreen because either
would answer the wrong question. That refusal is the point - the doctrine it
disproved ("shader effects render nothing on this port's software path") came
from an offscreen observation, and offscreen forces software by definition.
cc
133 lines
4.6 KiB
Rust
133 lines
4.6 KiB
Rust
//! Rust-side navigation history — the POC counterpart of Slint's
|
|
//! `NavState.can-back` / `can-forward` / request-back / request-forward.
|
|
//!
|
|
//! A simple stack (Vec + index): `record(view)` pushes a view (truncating
|
|
//! any forward entries), `back()` / `forward()` move the cursor. Every
|
|
//! mutation republishes `canBack` / `canForward` / `currentView` onto the
|
|
//! bridge.
|
|
//!
|
|
//! There is NO route table here, and that is deliberate: a view id is an
|
|
//! opaque `String`, and the only place the set of legal ids is enumerated is
|
|
//! `qml/shell/AppShell.qml`'s content `Loader` chain. Adding a route is
|
|
//! therefore a two-file change — the caller `record`s its id, AppShell grows
|
|
//! an arm for it — and nothing needs registering in this file. The failure
|
|
//! mode when the AppShell arm is forgotten is a BLANK content pane (the
|
|
//! ternary falls through to `""`), recoverable with Back; it is not a crash,
|
|
//! which is exactly why it is easy to miss.
|
|
//!
|
|
//! Ids in use: `home`, `library`, `local`, `localalbum`, `album`, `artist`,
|
|
//! `artistreleases`, `settings`, `search`, `playlist`, `discoverbrowse`,
|
|
//! `playlistbrowse`, `recentalbums`, `mostplayedalbums`, `label`,
|
|
//! `labelreleases`, `mix`, `mixtapes`, `collections`, `mixtapedetail`,
|
|
//! `discobuilder`, `blacklist`, `playlistmanager`.
|
|
|
|
use std::sync::Mutex;
|
|
|
|
use cxx_qt_lib::QString;
|
|
|
|
struct NavHistory {
|
|
entries: Vec<String>,
|
|
// Index of the CURRENT entry in `entries` (0 when only "home" exists).
|
|
index: usize,
|
|
}
|
|
|
|
static HISTORY: Mutex<Option<NavHistory>> = Mutex::new(None);
|
|
|
|
fn with_history<R>(f: impl FnOnce(&mut NavHistory) -> R) -> R {
|
|
let mut guard = HISTORY.lock().unwrap();
|
|
let history = guard.get_or_insert_with(|| NavHistory {
|
|
entries: vec!["home".to_string()],
|
|
index: 0,
|
|
});
|
|
f(history)
|
|
}
|
|
|
|
/// Push a view as the new current entry (no-op when it IS the current one).
|
|
pub fn record(view: &str) {
|
|
let (can_back, can_forward, current) = with_history(|h| {
|
|
if h.entries[h.index] != view {
|
|
h.entries.truncate(h.index + 1);
|
|
h.entries.push(view.to_string());
|
|
h.index += 1;
|
|
}
|
|
snapshot(h)
|
|
});
|
|
publish(can_back, can_forward, current);
|
|
}
|
|
|
|
/// The id of the entry the user is standing on.
|
|
///
|
|
/// Read-only, and the ONLY reader today is `playlist_qt::back_if_showing`
|
|
/// (contract §5.1): a delete may only navigate away when the deleted playlist
|
|
/// is the one whose detail page is open, or deleting a row from the Playlist
|
|
/// Manager throws the user off the manager. The bridge already publishes this
|
|
/// as `QbzShell.currentView`, but a Rust caller has no way to read a Qt
|
|
/// property back off the Qt thread — hence the accessor rather than a QML
|
|
/// round trip.
|
|
pub fn current_view() -> String {
|
|
with_history(|h| h.entries[h.index].clone())
|
|
}
|
|
|
|
/// Move one entry back, if possible.
|
|
pub fn back() {
|
|
let (can_back, can_forward, current) = with_history(|h| {
|
|
if h.index > 0 {
|
|
h.index -= 1;
|
|
}
|
|
snapshot(h)
|
|
});
|
|
publish(can_back, can_forward, current);
|
|
}
|
|
|
|
/// Move one entry forward, if possible.
|
|
pub fn forward() {
|
|
let (can_back, can_forward, current) = with_history(|h| {
|
|
if h.index + 1 < h.entries.len() {
|
|
h.index += 1;
|
|
}
|
|
snapshot(h)
|
|
});
|
|
publish(can_back, can_forward, current);
|
|
}
|
|
|
|
fn snapshot(h: &NavHistory) -> (bool, bool, String) {
|
|
(
|
|
h.index > 0,
|
|
h.index + 1 < h.entries.len(),
|
|
h.entries[h.index].clone(),
|
|
)
|
|
}
|
|
|
|
fn publish(can_back: bool, can_forward: bool, current: String) {
|
|
crate::shell_bridge::ui(move |mut b| {
|
|
b.as_mut().set_can_back(can_back);
|
|
b.as_mut().set_can_forward(can_forward);
|
|
b.as_mut().set_current_view(QString::from(current.as_str()));
|
|
});
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
// The history logic is exercised through the Mutex global; these tests
|
|
// run serially within one process, so drive it through the public API
|
|
// and re-derive expectations from fresh state each time. (The bridge
|
|
// publish hop is a no-op off the Qt thread — QT_THREAD unset.)
|
|
|
|
#[test]
|
|
fn record_back_forward_cycle() {
|
|
super::record("home");
|
|
super::record("album");
|
|
super::record("artist");
|
|
super::back();
|
|
super::back();
|
|
super::forward();
|
|
// Truncate-on-record: recording after back() drops forward entries.
|
|
super::back();
|
|
super::record("playlist");
|
|
// Now: home, playlist (artist/album dropped). Back once -> home.
|
|
super::back();
|
|
// Forward -> playlist again. No panics = the invariants hold.
|
|
super::forward();
|
|
}
|
|
}
|