Merge branch 'main' of https://github.com/an-anime-team/anime-launcher-sdk
This commit is contained in:
commit
9d6aeff526
3 changed files with 25 additions and 27 deletions
10
.gitignore
vendored
10
.gitignore
vendored
|
@ -1,9 +1,3 @@
|
||||||
/target
|
/target
|
||||||
|
/.vscode
|
||||||
|
Cargo.lock
|
||||||
# Added by cargo
|
|
||||||
#
|
|
||||||
# already existing elements were commented out
|
|
||||||
|
|
||||||
#/target
|
|
||||||
/Cargo.lock
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "anime-launcher-sdk"
|
name = "anime-launcher-sdk"
|
||||||
version = "0.2.2"
|
version = "0.2.5"
|
||||||
authors = ["Nikita Podvirnyy <suimin.tu.mu.ga.mi@gmail.com>"]
|
authors = ["Nikita Podvirnyy <suimin.tu.mu.ga.mi@gmail.com>"]
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
40
src/game.rs
40
src/game.rs
|
@ -13,7 +13,7 @@ use super::discord_rpc::*;
|
||||||
|
|
||||||
/// Try to run the game
|
/// 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)]
|
#[tracing::instrument(level = "info", ret)]
|
||||||
pub fn run() -> anyhow::Result<()> {
|
pub fn run() -> anyhow::Result<()> {
|
||||||
tracing::info!("Preparing to run the game");
|
tracing::info!("Preparing to run the game");
|
||||||
|
@ -146,35 +146,39 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
let variables = command
|
let variables = command
|
||||||
.get_envs()
|
.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);
|
.fold(String::new(), |acc, env| acc + " " + &env);
|
||||||
|
|
||||||
tracing::info!("Running the game with command: {variables} bash -c \"{bash_chain}\"");
|
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")]
|
#[cfg(feature = "discord-rpc")]
|
||||||
if config.launcher.discord_rpc.enabled {
|
let rpc = if config.launcher.discord_rpc.enabled {
|
||||||
let rpc = DiscordRpc::new(config.launcher.discord_rpc);
|
Some(DiscordRpc::new(config.launcher.discord_rpc))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "discord-rpc")]
|
||||||
|
if let Some(rpc) = &rpc {
|
||||||
rpc.update(RpcUpdates::Connect)?;
|
rpc.update(RpcUpdates::Connect)?;
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unused_must_use)]
|
loop {
|
||||||
std::thread::spawn(move || {
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
|
||||||
|
|
||||||
while let Ok(output) = Command::new("ps").arg("-A").stdout(Stdio::piped()).output() {
|
let output = Command::new("ps").arg("-A").stdout(Stdio::piped()).output()?;
|
||||||
let output = String::from_utf8_lossy(&output.stdout);
|
let output = String::from_utf8_lossy(&output.stdout);
|
||||||
|
|
||||||
if !output.contains("GenshinImpact.e") && !output.contains("unlocker.exe") {
|
if !output.contains("GenshinImpact.e") && !output.contains("unlocker.exe") {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
#[cfg(feature = "discord-rpc")]
|
||||||
}
|
if let Some(rpc) = &rpc {
|
||||||
|
rpc.update(RpcUpdates::Disconnect)?;
|
||||||
rpc.update(RpcUpdates::Disconnect);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue