The hint bar always named Xbox buttons, so someone at a keyboard was told to press buttons they did not have, and owners of other pads got the wrong letters. Hints now name an action, and the keys or button icons come from the input used last: keyboard, or an Xbox, PlayStation, Switch or Steam Deck controller. Behind Steam, every pad is Steam's virtual one. remus reads the file Steam names in SteamVirtualGamepadInfo to find the physical controller, matching the slot in the pad's name, as SDL does. Icons are Kenney's Input Prompts (CC0), with the licence beside them.
104 lines
4.0 KiB
Rust
104 lines
4.0 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,
|
|
"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));
|
|
}
|