feat: send DiscordRPC::Update messages each 3 seconds

This commit is contained in:
Observer KRypt0n_ 2023-08-17 12:27:58 +02:00
parent b2aa2d1fd8
commit 0f2163d22d
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
5 changed files with 31 additions and 1 deletions

View file

@ -50,6 +50,9 @@ pub enum RpcUpdates {
icon: String icon: String
}, },
/// Update RPC connection with already set activity params
Update,
/// Clear RPC activity /// Clear RPC activity
ClearActivity ClearActivity
} }
@ -102,6 +105,13 @@ impl DiscordRpc {
} }
} }
RpcUpdates::Update => {
if connected {
client.set_activity(Self::get_activity(&params))
.expect("Failed to update discord rpc activity");
}
}
RpcUpdates::ClearActivity => { RpcUpdates::ClearActivity => {
if connected { if connected {
client.clear_activity().expect("Failed to clear discord rpc activity"); client.clear_activity().expect("Failed to clear discord rpc activity");

View file

@ -302,6 +302,11 @@ pub fn run() -> anyhow::Result<()> {
if !output.contains("GenshinImpact.e") && !output.contains("YuanShen.exe") && !output.contains("unlocker.exe") { if !output.contains("GenshinImpact.e") && !output.contains("YuanShen.exe") && !output.contains("unlocker.exe") {
break; break;
} }
#[cfg(feature = "discord-rpc")]
if let Some(rpc) = &rpc {
rpc.update(RpcUpdates::Update)?;
}
} }
#[cfg(feature = "discord-rpc")] #[cfg(feature = "discord-rpc")]

View file

@ -246,6 +246,11 @@ pub fn run() -> anyhow::Result<()> {
if !output.contains("BH3.exe") { if !output.contains("BH3.exe") {
break; break;
} }
#[cfg(feature = "discord-rpc")]
if let Some(rpc) = &rpc {
rpc.update(RpcUpdates::Update)?;
}
} }
#[cfg(feature = "discord-rpc")] #[cfg(feature = "discord-rpc")]

View file

@ -228,9 +228,14 @@ pub fn run() -> anyhow::Result<()> {
let 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("BH3.exe") { if !output.contains("PGR.exe") {
break; break;
} }
#[cfg(feature = "discord-rpc")]
if let Some(rpc) = &rpc {
rpc.update(RpcUpdates::Update)?;
}
} }
#[cfg(feature = "discord-rpc")] #[cfg(feature = "discord-rpc")]

View file

@ -246,6 +246,11 @@ pub fn run() -> anyhow::Result<()> {
if !output.contains("StarRail.exe") { if !output.contains("StarRail.exe") {
break; break;
} }
#[cfg(feature = "discord-rpc")]
if let Some(rpc) = &rpc {
rpc.update(RpcUpdates::Update)?;
}
} }
#[cfg(feature = "discord-rpc")] #[cfg(feature = "discord-rpc")]