-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add explicit rich presence clearing; can be completely hidden w…
…ith `force = true`
- Loading branch information
Showing
4 changed files
with
41 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,48 @@ | ||
use crate::messages::events::event::{EventContext, OnEvent}; | ||
use crate::presence::packet::Packet; | ||
use crate::protocol::msgpack::Deserialize; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct ClearActivityEvent; | ||
pub struct ClearActivityEvent { | ||
force: bool, | ||
} | ||
|
||
impl OnEvent for ClearActivityEvent { | ||
fn on_event(self, ctx: &mut EventContext) -> crate::Result<()> { | ||
let sessions = ctx.cord.session_manager.sessions.read().unwrap(); | ||
let latest = sessions | ||
.iter() | ||
.filter(|s| s.1.last_activity.is_some()) | ||
.max_by_key(|s| { | ||
( | ||
s.1.last_activity.as_ref().is_some_and(|a| !a.is_idle), | ||
s.1.last_updated, | ||
) | ||
}); | ||
|
||
if let Some((_, session)) = latest { | ||
ctx.cord.rich_client.update(&Packet::new( | ||
ctx.cord.rich_client.pid, | ||
session.last_activity.as_ref(), | ||
))?; | ||
} else { | ||
if self.force { | ||
ctx.cord.rich_client.clear()?; | ||
} else { | ||
let sessions = ctx.cord.session_manager.sessions.read().unwrap(); | ||
let latest = sessions | ||
.iter() | ||
.filter(|s| s.1.last_activity.is_some()) | ||
.max_by_key(|s| { | ||
( | ||
s.1.last_activity.as_ref().is_some_and(|a| !a.is_idle), | ||
s.1.last_updated, | ||
) | ||
}); | ||
|
||
if let Some((_, session)) = latest { | ||
ctx.cord.rich_client.update(&Packet::new( | ||
ctx.cord.rich_client.pid, | ||
session.last_activity.as_ref(), | ||
))?; | ||
} else { | ||
ctx.cord.rich_client.clear()?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl Deserialize for ClearActivityEvent { | ||
fn deserialize( | ||
input: crate::protocol::msgpack::Value, | ||
) -> crate::Result<Self> { | ||
let force = input.as_bool().unwrap_or_default(); | ||
|
||
Ok(ClearActivityEvent { force }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters