From a3ada680dec082cc511325133cc574330394fea0 Mon Sep 17 00:00:00 2001 From: Paulemeister Date: Fri, 13 Oct 2023 18:24:40 +0200 Subject: [PATCH] added more paths for the socket --- .gitignore | 1 + src/ipc_unix.rs | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 96ef6c0..eb1d4ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target Cargo.lock +.vscode \ No newline at end of file diff --git a/src/ipc_unix.rs b/src/ipc_unix.rs index 332c950..17f0e64 100644 --- a/src/ipc_unix.rs +++ b/src/ipc_unix.rs @@ -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 = std::result::Result>; #[allow(dead_code)] @@ -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, } }