feat(slint): favorites Artists header Shuffle (random artist)
Add a Shuffle CircleAction to the Artists row-2 action cluster that opens a random artist from the visible set (random ARTIST, not a random album — matches Tauri). Adds favorites::random_visible_artist + the artists-shuffle handler routing through invoke_open_artist. cc
This commit is contained in:
3 files changed
+43
No files matched your search
@@ -809,6 +809,22 @@ pub fn random_visible_album(window: &AppWindow) -> Option<String> {
|
|||||||
model.row_data(idx).map(|a| a.id.to_string())
|
model.row_data(idx).map(|a| a.id.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A random artist id from the currently-visible favorites set. Tauri's
|
||||||
|
/// Artists header Shuffle opens a random ARTIST (not a random album).
|
||||||
|
pub fn random_visible_artist(window: &AppWindow) -> Option<String> {
|
||||||
|
let model = window.global::<FavoritesState>().get_artists_visible();
|
||||||
|
let n = model.row_count();
|
||||||
|
if n == 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let seed = std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.map(|d| d.as_nanos() as u64)
|
||||||
|
.unwrap_or(1);
|
||||||
|
let idx = (seed % n as u64) as usize;
|
||||||
|
model.row_data(idx).map(|a| a.id.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
// ---- Un-favorite in place: fade (set `removing`) then remove -----------
|
// ---- Un-favorite in place: fade (set `removing`) then remove -----------
|
||||||
|
|
||||||
/// Flag the matching track row(s) as removing so they fade out.
|
/// Flag the matching track row(s) as removing so they fade out.
|
||||||
|
|||||||
@@ -4362,6 +4362,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
// Artists header Shuffle = open a random visible artist (random
|
||||||
|
// ARTIST, not a random album — matches Tauri).
|
||||||
|
let weak = window.as_weak();
|
||||||
|
window
|
||||||
|
.global::<FavoritesActions>()
|
||||||
|
.on_artists_shuffle(move || {
|
||||||
|
if let Some(w) = weak.upgrade() {
|
||||||
|
if let Some(id) = favorites::random_visible_artist(&w) {
|
||||||
|
w.invoke_open_artist(id.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
{
|
{
|
||||||
// Playlist card actions: play / play-next / queue / share / favorite.
|
// Playlist card actions: play / play-next / queue / share / favorite.
|
||||||
let runtime = app_runtime.clone();
|
let runtime = app_runtime.clone();
|
||||||
|
|||||||
@@ -635,6 +635,19 @@ export component FavoritesView inherits Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if FavoritesState.active-tab == "artists"
|
||||||
|
&& FavoritesState.artists-visible.length > 0: HorizontalLayout {
|
||||||
|
spacing: 8px;
|
||||||
|
VerticalLayout {
|
||||||
|
alignment: center;
|
||||||
|
CircleAction {
|
||||||
|
icon: @image-url("../assets/icons/shuffle.svg");
|
||||||
|
clicked => {
|
||||||
|
FavoritesActions.artists-shuffle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle { horizontal-stretch: 1; }
|
Rectangle { horizontal-stretch: 1; }
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user