Shut down game, adb and BlueStacks after capture

This commit is contained in:
Jan-Peter von Hunnius 2026-08-22 10:35:36 +02:00
parent 3de8bf1f80
commit f829ad52a4
2 changed files with 27 additions and 0 deletions

View file

@ -37,6 +37,7 @@ struct CaptureConfig {
struct DeviceConfig {
serial: String,
wait_secs: u64,
shutdown_bluestacks: bool,
}
#[derive(Debug, Serialize, Deserialize)]
@ -76,6 +77,7 @@ impl Default for DeviceConfig {
Self {
serial: "127.0.0.1:5555".to_string(),
wait_secs: 180,
shutdown_bluestacks: true,
}
}
}
@ -728,6 +730,14 @@ async fn command_run(config: &CaptureConfig) -> Result<()> {
let _ = adb(config, &["reverse", remove_socket.as_str()]);
println!("device proxy settings restored");
println!("stopping {GAME_PACKAGE}");
let _ = adb_shell(config, &format!("am force-stop {GAME_PACKAGE}"));
let _ = run_adb(config, &["kill-server"]);
println!("adb stopped");
if config.device.shutdown_bluestacks {
close_bluestacks();
}
match outcome {
Ok(()) => {
println!("capture finished, run `cargo run --bin records -- best` to analyze");
@ -811,6 +821,21 @@ async fn command_clean(config: &CaptureConfig) -> Result<()> {
Ok(())
}
fn close_bluestacks() {
let silent = |args: &[&str]| {
let _ = Command::new("taskkill")
.args(args)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.status();
};
silent(&["/IM", "HD-Player.exe"]);
std::thread::sleep(Duration::from_secs(5));
silent(&["/F", "/IM", "HD-Player.exe"]);
println!("BlueStacks closed");
}
fn print_usage() {
println!(
"usage: capture <command>