Files
spotify/ui/app.slint
Tamas Csikel 7fd7e242a7
All checks were successful
release / release (push) Successful in 10m37s
0.2.0: play through Spotify Soloist
Spotify refuses librespot the audio keys ("error audio key 0 1",
librespot #1649), so nothing played. Playback now goes through Spotify
Soloist, Spotify's own headless Linux player:

- The TV downloads it from Spotify (redistribution is not allowed), keeps
  it fresh (builds expire after 90 days), runs and restarts it, and drives
  it over its local WebSocket API; its events feed Most szól.
- It needs the user's own Soloist API key: the key screen shows a QR code
  to a small page on the TV where the phone pastes it (or type it on the
  TV); asked once after sign-in, also in Settings. Then the TV is picked
  once in the phone's Spotify app (pairing); home shows that step.
- Soloist is the Connect device; librespot only signs in (pairing code)
  and browses. Its player, Connect and zeroconf are gone, and with them
  GStreamer.
- A track from a list plays and the next ones are queued (Soloist's play
  takes one URI). The queue panel is back (Soloist reports the queue).
- Settings: the player's state and key instead of quality/normalisation/
  autoplay (Soloist decides those).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 21:50:44 +01:00

207 lines
8.7 KiB
Plaintext

// Spotify for Fennec OS: the root window.
//
// Screens: "message" (start-up, errors), "signin" (QR code / Spotify app),
// "page" (every browsing screen: a LinePage built by src/page.rs),
// "nowplaying". Over them: the text input, the picker, the toast.
//
// Rust owns state and focus: every key goes to the `key` callback, except
// while a keyboard has the focus (the input overlay, the search keyboard).
import { TvWindow, Tv, SfText, GlassRect, MenuItem } from "@sf-ui/sf-ui.slint";
import { Line, Chip, Card, Check, QueueItem } from "types.slint";
import { LinePage } from "page.slint";
import { NowPlayingScreen } from "nowplaying.slint";
import { ConnectScreen, InputScreen, MessageScreen, KeyScreen } from "signin.slint";
import { SelectOverlay, Toast } from "overlays.slint";
export { Tv, SfText, MenuItem, Line, Chip, Card, Check, QueueItem }
export component App inherits TvWindow {
title: "Spotify";
forward-focus: keys;
// "message", "signin", "solokey", "page", "nowplaying"
in property <string> screen: "message";
// The key text (Slint's Key codes) and whether it repeats; true = handled.
callback key(string, bool) -> bool;
out property <float> message-t: self.screen == "message" ? 1 : 0;
animate message-t { duration: 420ms; easing: cubic-bezier(0.22, 1, 0.36, 1); }
out property <float> signin-t: self.screen == "signin" ? 1 : 0;
animate signin-t { duration: 420ms; easing: cubic-bezier(0.22, 1, 0.36, 1); }
out property <float> solokey-t: self.screen == "solokey" ? 1 : 0;
animate solokey-t { duration: 420ms; easing: cubic-bezier(0.22, 1, 0.36, 1); }
out property <float> page-t: self.screen == "page" ? 1 : 0;
animate page-t { duration: 420ms; easing: cubic-bezier(0.22, 1, 0.36, 1); }
out property <float> np-t: self.screen == "nowplaying" ? 1 : 0;
animate np-t { duration: 420ms; easing: cubic-bezier(0.22, 1, 0.36, 1); }
out property <float> input-t: self.input-open ? 1 : 0;
animate input-t { duration: 420ms; easing: cubic-bezier(0.22, 1, 0.36, 1); }
out property <float> select-t: self.select-open ? 1 : 0;
animate select-t { duration: 300ms; easing: cubic-bezier(0.3, 1.18, 0.4, 1); }
// Whatever an overlay would cover goes away first.
property <float> under: max(0, 1 - 1.6 * max(self.input-t, self.select-t));
// The outgoing screen goes first, the incoming one follows.
function vis(t: float) -> float {
clamp(t * 2 - 1, 0, 1)
}
keys := FocusScope {
key-pressed(event) => {
if root.input-open {
return input.key(event);
}
if root.screen == "page" && root.page-kb-focused && !root.select-open {
return page.kb-key(event);
}
if root.key(event.text, event.repeat) {
return accept;
}
reject
}
}
// ---- message ----
in property <bool> message-busy <=> message.busy;
in property <string> message-title <=> message.title;
in property <string> message-text <=> message.text;
message := MessageScreen {
alpha: root.vis(root.message-t);
visible: self.alpha > 0.001;
}
// ---- sign-in ----
in property <string> signin-device <=> signin.device;
in property <string> signin-code <=> signin.code;
in property <image> signin-qr <=> signin.qr;
in property <bool> signin-busy <=> signin.busy;
in property <string> signin-error <=> signin.error;
signin := ConnectScreen {
alpha: root.vis(root.signin-t);
visible: self.alpha > 0.001;
}
// ---- Soloist key ----
in property <image> solokey-qr <=> solokey.qr;
in property <string> solokey-url <=> solokey.url;
solokey := KeyScreen {
alpha: root.vis(root.solokey-t) * root.under;
visible: root.solokey-t > 0.001;
}
// ---- page ----
in property <[Line]> page-lines <=> page.lines;
in property <int> page-focus <=> page.focus-line;
in property <float> page-scroll <=> page.scroll;
in property <bool> page-show-nav <=> page.show-nav;
in property <[string]> page-nav-items <=> page.nav-items;
in property <int> page-nav-index <=> page.nav-index;
in property <bool> page-nav-focused <=> page.nav-focused;
in property <string> page-np-title <=> page.np-title;
in property <string> page-np-artist <=> page.np-artist;
in property <bool> page-np-playing <=> page.np-playing;
in property <bool> page-np-focused <=> page.np-focused;
in property <image> page-user-image <=> page.user-image;
in property <string> page-user-initial <=> page.user-initial;
in property <float> page-kb-y <=> page.kb-y;
in property <bool> page-kb-focused <=> page.kb-focused;
in property <string> page-kb-placeholder <=> page.kb-placeholder;
in-out property <string> page-query <=> page.query;
callback search-submitted(string);
callback search-changed(string);
changed page-query => {
root.search-changed(self.page-query);
}
callback search-exit-down();
callback search-exit-up();
callback search-cancelled();
public function page-kb-reset() {
page.kb-reset();
}
page := LinePage {
alpha: root.vis(root.page-t) * root.under;
visible: root.page-t > 0.001;
search-submitted(t) => { root.search-submitted(t); }
search-exit-down => { root.search-exit-down(); }
search-exit-up => { root.search-exit-up(); }
search-cancelled => { root.search-cancelled(); }
}
// ---- now playing ----
in property <string> np-title <=> np.title;
in property <string> np-artist <=> np.artist;
in property <string> np-album <=> np.album;
in property <image> np-cover <=> np.art;
in property <bool> np-explicit <=> np.explicit;
in property <bool> np-episode <=> np.episode;
in property <bool> np-playing <=> np.playing;
in property <bool> np-loading <=> np.loading;
in property <float> np-progress <=> np.progress;
in property <string> np-time <=> np.time;
in property <string> np-duration <=> np.duration;
in property <bool> np-shuffle <=> np.shuffle;
in property <int> np-repeat <=> np.repeat;
in property <int> np-liked <=> np.liked;
in property <int> np-focus <=> np.button;
in property <int> np-area <=> np.area;
in property <int> np-panel <=> np.panel;
in property <[string]> np-lyrics <=> np.lyrics;
in property <int> np-lyric-line <=> np.lyric-line;
in property <bool> np-lyrics-synced <=> np.lyrics-synced;
in property <string> np-lyrics-note <=> np.lyrics-note;
in property <[QueueItem]> np-queue <=> np.queue;
in property <string> np-queue-note <=> np.queue-note;
in property <string> np-device <=> np.device;
np := NowPlayingScreen {
alpha: root.vis(root.np-t) * root.under;
visible: root.np-t > 0.001;
}
// ---- text input ----
in property <bool> input-open;
in property <string> input-title <=> input.title;
in property <string> input-subtitle <=> input.subtitle;
in property <string> input-placeholder <=> input.placeholder;
in property <string> input-submit-label <=> input.submit-label;
in property <int> input-min-length <=> input.min-length;
in-out property <string> input-text <=> input.text;
in-out property <string> input-error <=> input.error;
callback input-submitted(string);
callback input-cancelled();
public function input-reset() {
input.reset();
}
input := InputScreen {
alpha: root.vis(root.input-t);
visible: root.input-t > 0.001;
submitted(t) => { root.input-submitted(t); }
cancelled => { root.input-cancelled(); }
}
// ---- picker ----
in property <bool> select-open;
in property <string> select-title <=> select.title;
in property <[MenuItem]> select-items <=> select.items;
in property <int> select-focus <=> select.focus-index;
select := SelectOverlay {
alpha: root.select-t;
visible: root.select-t > 0.001;
}
// ---- toast ----
in property <string> toast-text <=> toast.text;
in property <bool> toast-bad <=> toast.bad;
toast := Toast { }
// ---- glass, in drawing order (listed by src/main.rs) ----
out property <[GlassRect]> glass-signin: signin.glass;
out property <[GlassRect]> glass-solokey: solokey.glass;
out property <[GlassRect]> glass-page: page.glass;
out property <[GlassRect]> glass-page-keyboard: page.glass-keyboard;
out property <[GlassRect]> glass-np: np.glass;
out property <[GlassRect]> glass-input: input.glass;
out property <[GlassRect]> glass-input-keyboard: input.glass-keyboard;
out property <[GlassRect]> glass-select: select.glass;
out property <[GlassRect]> glass-toast: toast.glass;
}