Spotify for Fennec OS: native TV client
All checks were successful
release / release (push) Successful in 12m14s

Rust + Slint on sf-ui's Liquid Glass, with the page engine of Netflex TV.
librespot plays (GStreamer on the TV) and makes the TV a Spotify Connect
device; the Web API (token from the session) feeds the pages.

- Sign-in with the phone: a pairing code / QR code (spotify.com/pair,
  OAuth device flow) or picking the TV in the Spotify app (zeroconf).
- Home, search, library, playlist / album / liked songs / podcast pages,
  artist pages, settings; the user's picture top right.
- Now playing: seek, shuffle, repeat, like, synced lyrics, queue.
- package.sh builds x86-64 and aarch64 (Raspberry Pi); the Gitea CI
  releases both on a tag.
- tools/mock_server.py and SPOTIFY_MOCK for work without an account.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tamas Csikel
2026-11-03 17:23:34 +01:00
commit 3a66e0c7c7
34 changed files with 17083 additions and 0 deletions

154
src/screens/home.rs Normal file
View File

@@ -0,0 +1,154 @@
//! Kezdőlap: rows: recently played, your playlists (with the
//! liked songs first), your top artists and tracks, saved albums, new
//! releases. Every row loads on its own; a failing one just stays away.
use std::any::Any;
use crate::api::{Album, Artist, Playlist, Played, Track};
use crate::app::{Cx, Look, Screen};
use crate::page::{Frame, L, Spec};
use crate::screens::{self, album_card, artist_card, liked_card, playlist_card, track_card};
#[derive(Default)]
struct Data {
recent: Option<Vec<Played>>,
playlists: Option<Vec<Playlist>>,
liked_total: Option<u32>,
top_artists: Option<Vec<Artist>>,
top_tracks: Option<Vec<Track>>,
albums: Option<Vec<Album>>,
releases: Option<Vec<Album>>,
errors: Vec<String>,
}
pub struct Home {
data: Data,
loading: bool,
started: bool,
}
impl Home {
pub fn new() -> Home {
Home { data: Data::default(), loading: true, started: false }
}
fn load(&mut self, cx: &Cx) {
self.loading = true;
let api = cx.api();
cx.spawn::<Home, _>(
move || {
std::thread::scope(|s| {
let recent = s.spawn(|| api.recently_played());
let playlists = s.spawn(|| api.my_playlists(0));
let liked = s.spawn(|| api.liked(0));
let artists = s.spawn(|| api.top_artists());
let tracks = s.spawn(|| api.top_tracks());
let albums = s.spawn(|| api.saved_albums(0));
let releases = s.spawn(|| api.new_releases());
let mut d = Data::default();
let e = &mut d.errors;
let recent = keep(recent.join(), e);
let playlists = keep(playlists.join(), e).map(|p| p.list());
let liked_total = keep(liked.join(), e).map(|p| p.total);
let top_artists = keep(artists.join(), e);
let top_tracks = keep(tracks.join(), e);
let albums = keep(albums.join(), e).map(|p| p.list());
let releases = keep(releases.join(), e);
Data { recent, playlists, liked_total, top_artists, top_tracks, albums, releases, ..d }
})
},
|s, cx, d| {
s.data = d;
s.loading = false;
// The first picture of the page tints the background.
let first = s.data.recent.as_ref().and_then(|r| r.first()).map(|p| p.track.image(640)).unwrap_or_default();
cx.backdrop(&first, Look::Soft, "home");
},
);
}
}
/// A row's result: the data, or its error noted.
fn keep<T>(r: std::thread::Result<anyhow::Result<T>>, errors: &mut Vec<String>) -> Option<T> {
match r {
Ok(Ok(t)) => Some(t),
Ok(Err(e)) => {
log::warn!("home: {e:#}");
errors.push(crate::api::describe(&e));
None
}
Err(_) => None,
}
}
/// Recently played tracks, each once (newest first).
fn recent_cards(items: &[Played]) -> Vec<crate::page::C> {
let mut seen = std::collections::HashSet::new();
items
.iter()
.filter(|p| seen.insert(p.track.uri.clone()))
.take(20)
.map(|p| track_card(&p.track, p.context.as_ref().map(|c| c.uri.as_str()).unwrap_or("")))
.collect()
}
impl Screen for Home {
fn spec(&mut self, cx: &Cx) -> Spec {
if !self.started {
self.started = true;
self.load(cx);
}
let frame = Frame { nav: Some(0), ..Frame::default() };
let mut lines = Vec::new();
if self.loading {
lines.push(L::text("loading", "Betöltés…", "caption"));
return Spec { lines, frame };
}
let d = &self.data;
if let Some(r) = d.recent.as_ref().filter(|r| !r.is_empty()) {
lines.push(L::cards("recent", "Legutóbb játszott", "square", recent_cards(r)).captions());
}
let mut pl = vec![liked_card(d.liked_total)];
pl.extend(d.playlists.iter().flatten().map(playlist_card));
lines.push(L::cards("playlists", "Lejátszási listáid", "square", pl).captions());
if let Some(a) = d.top_artists.as_ref().filter(|a| !a.is_empty()) {
lines.push(L::cards("artists", "Kedvenc előadóid", "round", a.iter().map(artist_card).collect()).captions());
}
if let Some(t) = d.top_tracks.as_ref().filter(|t| !t.is_empty()) {
lines.push(L::cards("top", "Mostanában sokat hallgatod", "square", t.iter().map(|t| track_card(t, "")).collect()).captions());
}
if let Some(a) = d.albums.as_ref().filter(|a| !a.is_empty()) {
lines.push(L::cards("albums", "Elmentett albumaid", "square", a.iter().map(album_card).collect()).captions());
}
if let Some(a) = d.releases.as_ref().filter(|a| !a.is_empty()) {
lines.push(L::cards("releases", "Új megjelenések", "square", a.iter().map(album_card).collect()).captions());
}
if d.recent.is_none() && d.playlists.is_none() && d.top_artists.is_none() {
let why = d.errors.first().cloned().unwrap_or_default();
lines.push(L::notice("error", "bad", "Nem sikerült betölteni a kezdőlapot", why));
}
Spec { lines, frame }
}
fn activate(&mut self, cx: &Cx, line: &str, item: &str) {
if line == "top" {
// Top tracks play as a list, from the chosen one.
if let Some(t) = &self.data.top_tracks {
let i = t.iter().position(|x| item == format!("t:{}|", x.uri)).unwrap_or(0);
screens::play_from(cx, "", t, i);
return;
}
}
screens::open_card(cx, item);
}
fn shown(&mut self, cx: &Cx) {
let first = self.data.recent.as_ref().and_then(|r| r.first()).map(|p| p.track.image(640)).unwrap_or_default();
cx.backdrop(&first, Look::Soft, "home");
}
fn as_any(&mut self) -> &mut dyn Any {
self
}
}