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
+69
View File
@@ -0,0 +1,69 @@
use std::fs;
use std::io::Write;
use std::os::unix::fs::OpenOptionsExt;
use std::path::PathBuf;
use anyhow::{Context, Result};
use directories::ProjectDirs;
use serde::{Deserialize, Serialize};
/// Server credentials. `token` is md5(password + salt): not the password,
/// but enough to log in to this server, so the file is written 0600.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub url: String,
pub username: String,
pub salt: String,
pub token: String,
}
fn dirs() -> Option<ProjectDirs> {
ProjectDirs::from("", "", "remus")
}
fn config_path() -> Option<PathBuf> {
dirs().map(|d| d.config_dir().join("config.toml"))
}
pub fn cache_dir() -> Option<PathBuf> {
dirs().map(|d| d.cache_dir().to_path_buf())
}
pub fn load() -> Result<Option<Config>> {
let Some(path) = config_path() else { return Ok(None) };
match fs::read_to_string(&path) {
Ok(text) => Ok(Some(
toml::from_str(&text).with_context(|| format!("parsing {}", path.display()))?,
)),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(None),
Err(e) => Err(e).with_context(|| format!("reading {}", path.display())),
}
}
pub fn save(cfg: &Config) -> Result<()> {
let path = config_path().context("no config directory")?;
if let Some(dir) = path.parent() {
fs::create_dir_all(dir)?;
}
let text = toml::to_string(cfg)?;
// Write aside, sync, then rename over the old file, so a power cut
// mid-save leaves either the old login or the new one, never a torn file.
let tmp = path.with_extension("toml.tmp");
let mut f = fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.mode(0o600)
.open(&tmp)
.with_context(|| format!("writing {}", tmp.display()))?;
f.write_all(text.as_bytes())?;
f.sync_all()?;
fs::rename(&tmp, &path).with_context(|| format!("replacing {}", path.display()))?;
if let Some(dir) = path.parent()
&& let Ok(d) = fs::File::open(dir)
{
let _ = d.sync_all();
}
log::info!("saved login to {}", path.display());
Ok(())
}