Skip to content

Commit 144eff3

Browse files
committed
Implement Snap and Flathub compatibility on Linux
1 parent 5a24d2d commit 144eff3

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/connection_unix.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ static int MsgFlags = MSG_NOSIGNAL;
2626
static int MsgFlags = 0;
2727
#endif
2828

29+
// Directories where the discord-ipc socket might live
30+
// https://github.com/flathub/com.discordapp.Discord/wiki/Rich-Precense-(discord-rpc)
31+
static const char* DiscordIpcSocketDirs[] = {
32+
"", // Default
33+
"snap.discord", // https://snapcraft.io/discord
34+
"app/com.discordapp.Discord", // https://flathub.org/apps/com.discordapp.Discord
35+
};
36+
2937
static const char* GetTempPath()
3038
{
3139
const char* temp = getenv("XDG_RUNTIME_DIR");
@@ -63,13 +71,21 @@ bool BaseConnection::Open()
6371
setsockopt(self->sock, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval));
6472
#endif
6573

66-
for (int pipeNum = 0; pipeNum < 10; ++pipeNum) {
67-
snprintf(
68-
PipeAddr.sun_path, sizeof(PipeAddr.sun_path), "%s/discord-ipc-%d", tempPath, pipeNum);
69-
int err = connect(self->sock, (const sockaddr*)&PipeAddr, sizeof(PipeAddr));
70-
if (err == 0) {
71-
self->isOpen = true;
72-
return true;
74+
for (const char* dir : DiscordIpcSocketDirs) {
75+
const char* dir_prefix = dir ? "/" : "";
76+
for (int pipeNum = 0; pipeNum < 10; ++pipeNum) {
77+
snprintf(PipeAddr.sun_path,
78+
sizeof(PipeAddr.sun_path),
79+
"%s%s%s/discord-ipc-%d",
80+
tempPath,
81+
dir_prefix,
82+
dir,
83+
pipeNum);
84+
int err = connect(self->sock, (const sockaddr*)&PipeAddr, sizeof(PipeAddr));
85+
if (err == 0) {
86+
self->isOpen = true;
87+
return true;
88+
}
7389
}
7490
}
7591
self->Close();

0 commit comments

Comments
 (0)