feat: add a controller-driven Subsonic player for SteamOS

Browses a Subsonic library and plays it through mpv, driven by a
gamepad or keyboard. The UI scales from the window's physical height
rather than the compositor's scale factor, so it keeps its proportions
on a Steam Deck and on a 4K TV, where other players open small or
scale badly.
This commit is contained in:
Ansho Rei
2026-11-04 01:17:29 +01:00
commit 4105554f68
14 changed files with 10825 additions and 0 deletions
+92
View File
@@ -0,0 +1,92 @@
//! Scripted UI driving for development: replays actions and saves screenshots,
//! so layout can be checked at several resolutions without a controller.
//!
//! REMUS_DEV_SCRIPT="size:1280x800,wait:2000,shot:home.png,right,activate,wait:1500,shot:album.png,quit"
use std::time::Duration;
use slint::{ComponentHandle, PhysicalSize, Timer};
use crate::{Action, AppWindow, app};
pub fn run(ui: &AppWindow, script: &str) {
let steps: Vec<String> = script
.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect();
step(ui.as_weak(), steps, 0);
}
fn step(ui: slint::Weak<AppWindow>, steps: Vec<String>, i: usize) {
let Some(cmd) = steps.get(i).cloned() else { return };
let Some(win) = ui.upgrade() else { return };
let mut delay = Duration::from_millis(250);
match cmd.split_once(':') {
Some(("wait", ms)) => delay = Duration::from_millis(ms.parse().unwrap_or(1000)),
Some(("size", "full")) => {
win.window().set_fullscreen(true);
delay = Duration::from_millis(800);
}
Some(("size", wh)) => {
if let Some((w, h)) = wh.split_once('x') {
win.window()
.set_size(PhysicalSize::new(w.parse().unwrap_or(1280), h.parse().unwrap_or(800)));
}
delay = Duration::from_millis(500);
}
Some(("shot", path)) => {
let w = win.window();
log::info!(
"window: {:?} physical, scale factor {}, fullscreen {}, theme scale {}",
w.size(),
w.scale_factor(),
w.is_fullscreen(),
win.global::<crate::Theme>().get_s()
);
match w.take_snapshot() {
Ok(buf) => {
let img = image::RgbaImage::from_raw(buf.width(), buf.height(), buf.as_bytes().to_vec());
match img.map(|img| img.save(path)) {
Some(Ok(())) => log::info!("saved {path} ({}x{})", buf.width(), buf.height()),
Some(Err(e)) => log::error!("saving {path}: {e}"),
None => log::error!("snapshot buffer has the wrong size"),
}
}
Err(e) => log::error!("snapshot failed: {e}"),
}
}
Some(("login", creds)) => {
let mut parts = creds.splitn(3, '|').map(str::to_string);
let (url, user, pass) = (
parts.next().unwrap_or_default(),
parts.next().unwrap_or_default(),
parts.next().unwrap_or_default(),
);
app::with_app(move |app| app.dev_login(&url, &user, &pass));
}
_ => {
let action = match cmd.as_str() {
"up" => Action::Up,
"down" => Action::Down,
"left" => Action::Left,
"right" => Action::Right,
"activate" => Action::Activate,
"back" => Action::Back,
"queue" => Action::Queue,
"next" => Action::Next,
"play-pause" => Action::PlayPause,
"section-next" => Action::SectionNext,
"now-playing" => Action::NowPlaying,
"search" => Action::Search,
"quit" => Action::Quit,
other => {
log::warn!("unknown dev script step {other}");
Action::None
}
};
app::with_app(move |app| app.action(action));
}
}
Timer::single_shot(delay, move || step(ui, steps, i + 1));
}