Skip to content

Commit

Permalink
Merge pull request #28 from Paulemeister/main
Browse files Browse the repository at this point in the history
Account for flatpak and snap
  • Loading branch information
vionya authored Apr 17, 2024
2 parents 3d035d0 + a3ada68 commit 1056579
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
.vscode
25 changes: 18 additions & 7 deletions src/ipc_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ use std::{
// Environment keys to search for the Discord pipe
const ENV_KEYS: [&str; 4] = ["XDG_RUNTIME_DIR", "TMPDIR", "TMP", "TEMP"];

const APP_SUBPATHS: [&str; 4] = [
"",
"app/com.discordapp.Discord/",
"snap.discord-canary/",
"snap.discord/",
];

type Result<T> = std::result::Result<T, Box<dyn Error>>;

#[allow(dead_code)]
Expand Down Expand Up @@ -60,14 +67,18 @@ impl DiscordIpcClient {
impl DiscordIpc for DiscordIpcClient {
fn connect_ipc(&mut self) -> Result<()> {
for i in 0..10 {
let path = DiscordIpcClient::get_pipe_pattern().join(format!("discord-ipc-{}", i));

match UnixStream::connect(&path) {
Ok(socket) => {
self.socket = Some(socket);
return Ok(());
for subpath in APP_SUBPATHS {
let path = DiscordIpcClient::get_pipe_pattern()
.join(subpath)
.join(format!("discord-ipc-{}", i));

match UnixStream::connect(&path) {
Ok(socket) => {
self.socket = Some(socket);
return Ok(());
}
Err(_) => continue,
}
Err(_) => continue,
}
}

Expand Down

0 comments on commit 1056579

Please sign in to comment.