config.toml now holds a list of [[server]] logins and the active one. The single-login file of earlier versions loads as the only entry. Settings lists the servers first: confirm switches, the queue button pressed twice removes, and Add server opens the login form, which can now be cancelled. Removing the last login returns to the login screen. A switch saves the queue of the server being left, stops the player and restores the other server's saved queue paused. Player events sent before the stop are dropped by an epoch, and cover loads started for the old server by a generation, so nothing of one server shows on the other. Covers are cached on disk per server, keyed like the saved queue. The shoulder triggers wrap around the sections, which puts Settings one press from the first section.
108 lines
4.2 KiB
Rust
108 lines
4.2 KiB
Rust
//! 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(("prompts", kind)) => {
|
|
use crate::prompts::Family;
|
|
let family = match kind {
|
|
"xbox" => Some(Family::Xbox),
|
|
"playstation" => Some(Family::PlayStation),
|
|
"switch" => Some(Family::Switch),
|
|
"steamdeck" => Some(Family::SteamDeck),
|
|
_ => None,
|
|
};
|
|
app::with_app(move |app| app.pad_present(family));
|
|
}
|
|
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,
|
|
"section-prev" => Action::SectionPrev,
|
|
"now-playing" => Action::NowPlaying,
|
|
"search" => Action::Search,
|
|
"quit" => Action::Quit,
|
|
"volume-up" => Action::VolumeUp,
|
|
"volume-down" => Action::VolumeDown,
|
|
"mute" => Action::ToggleMute,
|
|
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));
|
|
}
|