cli: summit run <id> --enhance (launch, enhance the live window, stop both), enhance window:<title>, --no-watermark, profile --target-hz/--model
This commit is contained in:
1 parent
99403534ae
commit
cf3d148a10
1 file changed
+62
-13
@@ -20,7 +20,21 @@ enum Cmd {
|
||||
/// Top played games from Steam playtime (the Home view)
|
||||
Home { #[arg(short, default_value_t = 10)] n: usize },
|
||||
/// Launch an entry: apply its display profile, run it, track the time played
|
||||
Run { id: String, #[arg(last = true)] cmd: Vec<String> },
|
||||
Run {
|
||||
id: String,
|
||||
/// Also run the frame-gen/upscale engine on the game's window, live (X11), with the game's profile.
|
||||
/// Both stop when either exits.
|
||||
#[arg(long)] enhance: bool,
|
||||
/// With --enhance: which window to take instead of the game process's own
|
||||
/// (part of its title, class:NAME, pid:N or xid:N)
|
||||
#[arg(long)] window: Option<String>,
|
||||
/// With --enhance: seconds to wait for the game's window to open
|
||||
#[arg(long, default_value_t = 60)] wait: u32,
|
||||
/// With --enhance: hide the "summit - git.molberg.cloud/alex/summit" line in the corner
|
||||
#[arg(long)] no_watermark: bool,
|
||||
/// The command to run. Not needed for an entry added with `summit add`.
|
||||
#[arg(last = true)] cmd: Vec<String>,
|
||||
},
|
||||
/// Add a game or app by hand
|
||||
Add { title: String, path: std::path::PathBuf, #[arg(long)] software: bool },
|
||||
/// Add an entry to the Home screen
|
||||
@@ -37,8 +51,10 @@ enum Cmd {
|
||||
Enhance {
|
||||
/// Profile id to take settings from
|
||||
#[arg(long, default_value = "default")] profile: String,
|
||||
/// ps5 | capture:<name|index> | window:<app> | a video file
|
||||
/// ps5 | capture:<name|index> | window:<title, class:NAME, pid:N or xid:N> | a video file
|
||||
source: String,
|
||||
/// Hide the "summit - git.molberg.cloud/alex/summit" line in the corner of the video window
|
||||
#[arg(long)] no_watermark: bool,
|
||||
/// Render to a file instead of a window (needs a file source)
|
||||
#[arg(long)] out: Option<std::path::PathBuf>,
|
||||
#[arg(long)] max_ticks: Option<u32>,
|
||||
@@ -63,6 +79,10 @@ enum ProfileCmd {
|
||||
#[arg(long)] upscaler: Option<String>,
|
||||
#[arg(long)] framegen: Option<String>,
|
||||
#[arg(long)] multiplier: Option<u8>,
|
||||
/// Engine output rate: 60, 90 or 120
|
||||
#[arg(long)] target_hz: Option<u32>,
|
||||
/// RIFE model for the engine, e.g. 4.22.lite
|
||||
#[arg(long)] model: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -105,14 +125,10 @@ fn main() -> Result<()> {
|
||||
st.custom.push(state::Custom { id: id.clone(), title, path: path.canonicalize()?.to_string_lossy().into_owned(), software });
|
||||
state::save(&st)?; println!("added {id}");
|
||||
}
|
||||
Cmd::Enhance { profile, source, out, max_ticks, dry_run } => {
|
||||
Cmd::Enhance { profile, source, no_watermark, out, max_ticks, dry_run } => {
|
||||
let eng = engine::find_engine().ok_or_else(|| anyhow::anyhow!("engine not found: set SUMMIT_ENGINE to the engine/ folder"))?;
|
||||
let src = match source.as_str() {
|
||||
"ps5" => engine::Source::Ps5,
|
||||
s if s.starts_with("capture:") => engine::Source::Capture(s[8..].into()),
|
||||
s if s.starts_with("window:") => engine::Source::Window(s[7..].into()),
|
||||
f => engine::Source::File(f.into()),
|
||||
};
|
||||
let src = engine::parse_source(&source).map_err(|e| anyhow::anyhow!(e))?;
|
||||
anyhow::ensure!(out.is_none() || matches!(src, engine::Source::File(_)), "--out needs a video file as the source");
|
||||
let p = profile::load(&profile)?;
|
||||
let mut args = engine::plan(&eng, &src, &p, out.is_none(), out.as_deref(), max_ticks);
|
||||
// Instant replay only exists while playing on screen. Lengths come from the launcher's settings page;
|
||||
@@ -121,10 +137,12 @@ fn main() -> Result<()> {
|
||||
let ui = summit_core::ui::load();
|
||||
args.extend(engine::clip_args(ui.replay_seconds, ui.clip_seconds));
|
||||
}
|
||||
if out.is_none() && no_watermark { args.extend(["--watermark".to_string(), "off".to_string()]); }
|
||||
args.extend(engine::extra_args(std::env::var("SUMMIT_ENGINE_ARGS").ok().as_deref()));
|
||||
let py = engine::python(&eng);
|
||||
println!("{} {}", py.display(), args.join(" "));
|
||||
if !dry_run {
|
||||
let st = std::process::Command::new(&py).args(&args).status()?;
|
||||
let st = std::process::Command::new(&py).args(&args).env("SMOOVPLAY_TITLE", "Summit").status()?;
|
||||
anyhow::ensure!(st.success(), "engine exited with {st}");
|
||||
}
|
||||
}
|
||||
@@ -145,9 +163,14 @@ fn main() -> Result<()> {
|
||||
for c in cmds { println!("would run: {}", c.join(" ")); }
|
||||
}
|
||||
}
|
||||
Cmd::Run { id, cmd } => {
|
||||
Cmd::Run { id, enhance, window, wait, no_watermark, mut cmd } => {
|
||||
if cmd.is_empty() { // an entry added with `summit add` knows its own path
|
||||
if let Some(c) = state::load().custom.iter().find(|c| c.id == id) { cmd = vec![c.path.clone()]; }
|
||||
}
|
||||
anyhow::ensure!(!cmd.is_empty(), "give the command after --, e.g. summit run my-game -- ./game.sh");
|
||||
let p = profile::load(&id)?;
|
||||
// Found before the game starts, so a missing engine never leaves a game running without it.
|
||||
let eng = if enhance { Some(engine::find_engine().ok_or_else(|| anyhow::anyhow!("engine not found: set SUMMIT_ENGINE to the engine/ folder"))?) } else { None };
|
||||
let (s, d) = (display::detect_session(), display::detect_desktop());
|
||||
let plan = display::plan(s, d, &p);
|
||||
if plan.is_empty() && p.monitor.is_some() { eprintln!("note: no display control for {s:?}/{d:?}; launching without mode change"); }
|
||||
@@ -155,7 +178,31 @@ fn main() -> Result<()> {
|
||||
let start = std::time::Instant::now();
|
||||
let mut child = std::process::Command::new(&cmd[0]);
|
||||
child.args(&cmd[1..]).args(&p.launch_args).envs(display::launch_env(s, &p));
|
||||
let status = child.status()?;
|
||||
// A game given by its full path is started from its own folder: many look for their data there.
|
||||
if let Some(dir) = std::path::Path::new(&cmd[0]).parent().filter(|d| d.is_absolute() && d.is_dir()) { child.current_dir(dir); }
|
||||
let status = if let Some(eng) = eng {
|
||||
let mut game = child.spawn()?;
|
||||
let live = engine::Live { wait_secs: wait, watermark: if no_watermark { Some(false) } else { None } };
|
||||
let mut args = engine::run_enhance_plan(&eng, game.id(), window.as_deref(), &p, &live);
|
||||
if summit_core::ui::path().map_or(false, |p| p.exists()) {
|
||||
let ui = summit_core::ui::load();
|
||||
args.extend(engine::clip_args(ui.replay_seconds, ui.clip_seconds));
|
||||
}
|
||||
args.extend(engine::extra_args(std::env::var("SUMMIT_ENGINE_ARGS").ok().as_deref()));
|
||||
let py = engine::python(&eng);
|
||||
println!("{} {}", py.display(), args.join(" "));
|
||||
let grace = std::time::Duration::from_secs(8);
|
||||
let mut eng_proc = match std::process::Command::new(&py).args(&args).env("SMOOVPLAY_TITLE", "Summit").spawn() {
|
||||
Ok(c) => c,
|
||||
Err(e) => { let _ = engine::stop(&mut game, grace); anyhow::bail!("could not start the engine ({}): {e}", py.display()); }
|
||||
};
|
||||
let (who, status) = engine::supervise(&mut game, &mut eng_proc, grace)?;
|
||||
match who {
|
||||
engine::Ended::Game => println!("the game exited; the engine was stopped"),
|
||||
engine::Ended::Engine => println!("the engine exited ({}); the game was stopped", eng_proc.wait()?),
|
||||
}
|
||||
status
|
||||
} else { child.status()? };
|
||||
let secs = start.elapsed().as_secs();
|
||||
let now = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH)?.as_secs();
|
||||
let mut st = state::load(); st.record_session(&id, secs, now); state::save(&st)?;
|
||||
@@ -164,7 +211,7 @@ fn main() -> Result<()> {
|
||||
Cmd::Profile { cmd: ProfileCmd::Show { id } } => {
|
||||
print!("{}", toml::to_string_pretty(&profile::load(&id)?)?);
|
||||
}
|
||||
Cmd::Profile { cmd: ProfileCmd::Set { id, monitor, width, height, refresh, fullscreen, focus, upscaler, framegen, multiplier } } => {
|
||||
Cmd::Profile { cmd: ProfileCmd::Set { id, monitor, width, height, refresh, fullscreen, focus, upscaler, framegen, multiplier, target_hz, model } } => {
|
||||
let mut p = profile::load(&id)?;
|
||||
if monitor.is_some() { p.monitor = monitor; }
|
||||
if width.is_some() { p.width = width; }
|
||||
@@ -175,6 +222,8 @@ fn main() -> Result<()> {
|
||||
if let Some(v) = upscaler { p.upscaler = v; }
|
||||
if let Some(v) = framegen { p.framegen = v; }
|
||||
if let Some(v) = multiplier { p.framegen_multiplier = v; }
|
||||
if let Some(v) = target_hz { anyhow::ensure!([60, 90, 120].contains(&v), "--target-hz is 60, 90 or 120"); p.target_hz = Some(v); }
|
||||
if model.is_some() { p.model = model; }
|
||||
println!("saved {}", profile::save(&id, &p)?.display());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user