0.2.0: play through Spotify Soloist
All checks were successful
release / release (push) Successful in 10m37s
All checks were successful
release / release (push) Successful in 10m37s
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>
This commit is contained in:
118
src/app.rs
118
src/app.rs
@@ -139,6 +139,10 @@ pub struct State {
|
||||
pub np: NowPlaying,
|
||||
/// The nav focus sits on the "now playing" capsule.
|
||||
np_capsule: bool,
|
||||
/// The player (Soloist).
|
||||
pub solo: crate::soloist::Status,
|
||||
/// The key page while the key screen is open.
|
||||
keyserver: Option<crate::keyserver::KeyServer>,
|
||||
}
|
||||
|
||||
pub struct Inner {
|
||||
@@ -195,6 +199,9 @@ impl<'a> Cx<'a> {
|
||||
pub fn user(&self) -> User {
|
||||
self.c.state.borrow().user.clone()
|
||||
}
|
||||
pub fn solo(&self) -> crate::soloist::Status {
|
||||
self.c.state.borrow().solo.clone()
|
||||
}
|
||||
pub fn cfg(&self) -> Config {
|
||||
self.c.state.borrow().cfg.clone()
|
||||
}
|
||||
@@ -293,6 +300,8 @@ impl Controller {
|
||||
select: None,
|
||||
np: NowPlaying::default(),
|
||||
np_capsule: false,
|
||||
solo: crate::soloist::Status::Starting,
|
||||
keyserver: None,
|
||||
};
|
||||
let c = Controller(Rc::new(Inner {
|
||||
ui: ui.as_weak(),
|
||||
@@ -381,6 +390,7 @@ impl Controller {
|
||||
match ev {
|
||||
Event::Status(s) => self.on_status(s),
|
||||
Event::Pair(p) => self.on_pair(p),
|
||||
Event::Solo(s) => self.on_solo(s),
|
||||
other => nowplaying::on_event(self, other),
|
||||
}
|
||||
}
|
||||
@@ -441,12 +451,12 @@ impl Controller {
|
||||
}
|
||||
c.show_user(&user);
|
||||
c.state.borrow_mut().user = user;
|
||||
c.section_now(0);
|
||||
c.after_sign_in();
|
||||
}
|
||||
Err(e) => {
|
||||
// Browsing may still fail, but playback works: go on.
|
||||
log::warn!("me: {e:#}");
|
||||
c.section_now(0);
|
||||
c.after_sign_in();
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -467,6 +477,107 @@ impl Controller {
|
||||
}
|
||||
}
|
||||
|
||||
/// Signed in: the home page, or first the Soloist key if there is none.
|
||||
fn after_sign_in(&self) {
|
||||
if self.state.borrow().cfg.soloist_key.trim().is_empty() {
|
||||
self.open_key_screen();
|
||||
} else {
|
||||
self.section_now(0);
|
||||
}
|
||||
}
|
||||
|
||||
/// The player's state changed.
|
||||
fn on_solo(&self, s: crate::soloist::Status) {
|
||||
let changed = self.state.borrow().solo != s;
|
||||
self.state.borrow_mut().solo = s.clone();
|
||||
if !changed {
|
||||
return;
|
||||
}
|
||||
if let crate::soloist::Status::Failed(msg) = &s {
|
||||
self.toast(msg, true);
|
||||
}
|
||||
// Home and settings show it.
|
||||
if self.state.borrow().screen == "page" {
|
||||
self.rebuild();
|
||||
}
|
||||
crate::nowplaying::sync(self);
|
||||
}
|
||||
|
||||
/// The Soloist key screen: a QR code to a page where the phone pastes
|
||||
/// the key; OK types it on the TV instead; Back: later.
|
||||
pub fn open_key_screen(&self) {
|
||||
let server = crate::keyserver::start(move |key| {
|
||||
let _ = slint::invoke_from_event_loop(move || {
|
||||
if let Some(c) = CONTROLLER.with(|k| k.borrow().clone()) {
|
||||
c.set_solo_key(&key);
|
||||
}
|
||||
});
|
||||
});
|
||||
let url = match server {
|
||||
Ok(s) => {
|
||||
let url = s.url.clone();
|
||||
self.state.borrow_mut().keyserver = Some(s);
|
||||
url
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("key page: {e:#}");
|
||||
String::new()
|
||||
}
|
||||
};
|
||||
if let Some(ui) = self.ui() {
|
||||
ui.set_solokey_url(url.trim_start_matches("http://").trim_end_matches('/').into());
|
||||
ui.set_solokey_qr(if url.is_empty() { Default::default() } else { qr_image(&url).unwrap_or_default() });
|
||||
}
|
||||
self.clear_backdrop();
|
||||
self.show("solokey");
|
||||
}
|
||||
|
||||
/// A new Soloist key (from the phone or the TV keyboard).
|
||||
pub fn set_solo_key(&self, key: &str) {
|
||||
let key = key.trim().to_string();
|
||||
if key.len() < 16 {
|
||||
self.toast("Ez nem tűnik kulcsnak.", true);
|
||||
return;
|
||||
}
|
||||
{
|
||||
let mut st = self.state.borrow_mut();
|
||||
st.cfg.soloist_key = key.clone();
|
||||
st.cfg.save();
|
||||
}
|
||||
self.engine.set_key(&key);
|
||||
self.toast("Kulcs elmentve, indul a lejátszó", false);
|
||||
if self.state.borrow().screen == "solokey" {
|
||||
self.close_key_screen();
|
||||
}
|
||||
}
|
||||
|
||||
fn close_key_screen(&self) {
|
||||
self.state.borrow_mut().keyserver = None;
|
||||
if self.state.borrow().stack.is_empty() {
|
||||
self.section_now(0);
|
||||
} else {
|
||||
self.back_to_pages();
|
||||
}
|
||||
}
|
||||
|
||||
fn key_screen_key(&self, a: Action) {
|
||||
match a {
|
||||
Action::Back => self.close_key_screen(),
|
||||
Action::Ok => {
|
||||
let req = Input {
|
||||
title: "Spotify Soloist kulcs".into(),
|
||||
subtitle: "developer.spotify.com/dashboard/soloist".into(),
|
||||
placeholder: "API-kulcs".into(),
|
||||
value: String::new(),
|
||||
submit: "Mentés".into(),
|
||||
min: 16,
|
||||
};
|
||||
self.open_input(req, Rc::new(|c: &Controller, text: String| c.set_solo_key(&text)));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// The user's picture (or initial) in the top right corner.
|
||||
fn show_user(&self, user: &User) {
|
||||
let Some(ui) = self.ui() else { return };
|
||||
@@ -822,7 +933,7 @@ impl Controller {
|
||||
}
|
||||
|
||||
/// The nav focus and the "now playing" capsule.
|
||||
fn sync_nav(&self) {
|
||||
pub fn sync_nav(&self) {
|
||||
let Some(ui) = self.ui() else { return };
|
||||
let st = self.state.borrow();
|
||||
let nav_focus = st.stack.last().is_some_and(|e| e.view.focus == Focus::Nav);
|
||||
@@ -876,6 +987,7 @@ impl Controller {
|
||||
}
|
||||
let screen = self.state.borrow().screen;
|
||||
match screen {
|
||||
"solokey" => self.key_screen_key(a),
|
||||
"message" | "signin" => {
|
||||
if a == Action::Back {
|
||||
let _ = slint::quit_event_loop();
|
||||
|
||||
Reference in New Issue
Block a user