Skip to content

Commit

Permalink
fix: send valid payload to clear presence
Browse files Browse the repository at this point in the history
  • Loading branch information
vyfor committed Apr 14, 2024
1 parent 03dbd45 commit 5b49d82
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/ipc/platform/unix_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl Connection for RichClient {
};
pipe.write_all(&payload)?;
}

Ok(())
}

Expand All @@ -65,6 +66,7 @@ impl Connection for RichClient {
pipe.write_all(&utils::encode(2, 0))?;
pipe.shutdown(std::net::Shutdown::Both)?;
}

Ok(())
}

Expand All @@ -90,6 +92,17 @@ impl Connection for RichClient {
}

fn clear(&mut self) -> io::Result<()> {
self.write(1, None)
self.write(
1,
Some(
Packet {
pid: std::process::id(),
activity: None,
}
.to_json()
.unwrap()
.as_bytes(),
),
)
}
}
17 changes: 16 additions & 1 deletion src/ipc/platform/windows_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::os::windows::fs::OpenOptionsExt;

use crate::ipc::client::{Connection, RichClient};
use crate::ipc::utils;
use crate::rpc::packet::Packet;

impl Connection for RichClient {
fn connect(client_id: u64) -> Result<Self, Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -44,6 +45,7 @@ impl Connection for RichClient {
};
pipe.write_all(&payload)?;
}

Ok(())
}

Expand All @@ -64,6 +66,7 @@ impl Connection for RichClient {
if let Some(mut pipe) = self.pipe.take() {
pipe.write_all(&utils::encode(2, 0))?;
}

Ok(())
}

Expand All @@ -84,10 +87,22 @@ impl Connection for RichClient {
if packet.activity != self.last_activity {
return self.write(1, Some(packet.to_json().unwrap().as_bytes()));
}

Ok(())
}

fn clear(&mut self) -> io::Result<()> {
self.write(1, None)
self.write(
1,
Some(
Packet {
pid: std::process::id(),
activity: None,
}
.to_json()
.unwrap()
.as_bytes(),
),
)
}
}

0 comments on commit 5b49d82

Please sign in to comment.