diff --git a/capture.toml.example b/capture.toml.example index e02e287..2bb2955 100644 --- a/capture.toml.example +++ b/capture.toml.example @@ -9,6 +9,8 @@ serial = "127.0.0.1:5555" # How long to wait for the emulator to come online before giving up wait_secs = 180 +# Close BlueStacks automatically after the capture finished +shutdown_bluestacks = true [paths] # Path to adb.exe (empty = auto-detect from LOCALAPPDATA, then PATH) diff --git a/src/capture/windows.rs b/src/capture/windows.rs index eab1044..748f095 100644 --- a/src/capture/windows.rs +++ b/src/capture/windows.rs @@ -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