@@ -26,6 +26,14 @@ static int MsgFlags = MSG_NOSIGNAL;
2626static 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+
2937static 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