0.2.3
- updated `game::run()` to freeze current thread while the game is running
This commit is contained in:
parent
6fa47d0338
commit
b76b97bc97
3 changed files with 25 additions and 27 deletions
10
.gitignore
vendored
10
.gitignore
vendored
|
@ -1,9 +1,3 @@
|
|||
/target
|
||||
|
||||
|
||||
# Added by cargo
|
||||
#
|
||||
# already existing elements were commented out
|
||||
|
||||
#/target
|
||||
/Cargo.lock
|
||||
/.vscode
|
||||
Cargo.lock
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "anime-launcher-sdk"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
authors = ["Nikita Podvirnyy <suimin.tu.mu.ga.mi@gmail.com>"]
|
||||
license = "GPL-3.0"
|
||||
readme = "README.md"
|
||||
|
|
40
src/game.rs
40
src/game.rs
|
@ -13,7 +13,7 @@ use super::discord_rpc::*;
|
|||
|
||||
/// Try to run the game
|
||||
///
|
||||
/// If `debug = true`, then the game will be run in the new terminal window
|
||||
/// This function will freeze thread it was called from while the game is running
|
||||
#[tracing::instrument(level = "info", ret)]
|
||||
pub fn run() -> anyhow::Result<()> {
|
||||
tracing::info!("Preparing to run the game");
|
||||
|
@ -146,35 +146,39 @@ pub fn run() -> anyhow::Result<()> {
|
|||
|
||||
let variables = command
|
||||
.get_envs()
|
||||
.map(|(key, value)| format!("{:?}=\"{:?}\"", key, value.unwrap_or_default()))
|
||||
.map(|(key, value)| format!("{:?}=\"{:?}\"", key.to_string_lossy(), value.unwrap_or_default().to_string_lossy()))
|
||||
.fold(String::new(), |acc, env| acc + " " + &env);
|
||||
|
||||
tracing::info!("Running the game with command: {variables} bash -c \"{bash_chain}\"");
|
||||
|
||||
command.current_dir(config.game.path).spawn()?;
|
||||
command.current_dir(config.game.path).spawn()?.wait_with_output()?;
|
||||
|
||||
#[cfg(feature = "discord-rpc")]
|
||||
if config.launcher.discord_rpc.enabled {
|
||||
let rpc = DiscordRpc::new(config.launcher.discord_rpc);
|
||||
let rpc = if config.launcher.discord_rpc.enabled {
|
||||
Some(DiscordRpc::new(config.launcher.discord_rpc))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
#[cfg(feature = "discord-rpc")]
|
||||
if let Some(rpc) = &rpc {
|
||||
rpc.update(RpcUpdates::Connect)?;
|
||||
}
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
std::thread::spawn(move || {
|
||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||
loop {
|
||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||
|
||||
while let Ok(output) = Command::new("ps").arg("-A").stdout(Stdio::piped()).output() {
|
||||
let output = String::from_utf8_lossy(&output.stdout);
|
||||
let output = Command::new("ps").arg("-A").stdout(Stdio::piped()).output()?;
|
||||
let output = String::from_utf8_lossy(&output.stdout);
|
||||
|
||||
if !output.contains("GenshinImpact.e") && !output.contains("unlocker.exe") {
|
||||
break;
|
||||
}
|
||||
if !output.contains("GenshinImpact.e") && !output.contains("unlocker.exe") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||
}
|
||||
|
||||
rpc.update(RpcUpdates::Disconnect);
|
||||
});
|
||||
#[cfg(feature = "discord-rpc")]
|
||||
if let Some(rpc) = &rpc {
|
||||
rpc.update(RpcUpdates::Disconnect)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue