jagrosh/DiscordIPC

README example is broken in Ubuntu

MrPowerGamerBR opened this issue · 9 comments

object Main {
    @JvmStatic
    fun main(args: Array<String>) {
        val client = IPCClient(384465696496549888L)
        client.setListener(object : IPCListener {
            override fun onReady(client: IPCClient?) {
                val builder = RichPresence.Builder()
                builder.setState("West of House")
                    .setDetails("Frustration level: Over 9000")
                    .setStartTimestamp(OffsetDateTime.now())
                    .setLargeImage("canary-large", "Discord Canary")
                    .setSmallImage("ptb-small", "Discord PTB")
                    .setParty("party1234", 1, 6)
                    .setMatchSecret("xyzzy")
                    .setJoinSecret("join")
                    .setSpectateSecret("look")
                client!!.sendRichPresence(builder.build())
            }
        })
        client.connect()
    }
}
Exception in thread "main" java.lang.RuntimeException: java.net.SocketException: Socket file not found: /run/user/1000/snap.intellij-idea-community/discord-ipc-0
	at com.jagrosh.discordipc.entities.pipe.Pipe.createPipe(Pipe.java:167)
	at com.jagrosh.discordipc.entities.pipe.Pipe.openPipe(Pipe.java:67)
	at com.jagrosh.discordipc.IPCClient.connect(IPCClient.java:116)
	at com.mrpowergamerbr.powerrp.Main.main(Main.kt:34)
Caused by: java.net.SocketException: Socket file not found: /run/user/1000/snap.intellij-idea-community/discord-ipc-0
	at org.newsclub.net.unix.AFUNIXSocketImpl.validateSocketFile(AFUNIXSocketImpl.java:164)
	at org.newsclub.net.unix.AFUNIXSocketImpl.connect(AFUNIXSocketImpl.java:154)
	at org.newsclub.net.unix.AFUNIXSocket.connect(AFUNIXSocket.java:138)
	at org.newsclub.net.unix.AFUNIXSocket.connect(AFUNIXSocket.java:117)
	at com.jagrosh.discordipc.entities.pipe.UnixPipe.<init>(UnixPipe.java:46)
	at com.jagrosh.discordipc.entities.pipe.Pipe.createPipe(Pipe.java:163)
	... 3 more

I'm running the code directly from IDEA, maybe that's why it isn't working? Discord's IPC socket is in ./run/user/1000/discord-ipc-0 on my system

Just for fun I created a symlink ln -s /run/user/1000/discord-ipc-0 /run/user/1000/snap.intellij-idea-community/discord-ipc-0, and...

image

If it's not too much to ask, could you add this line to the program near the start and report back what it gives you?

println(System.getProperty("java.io.tmpdir"))

I decided to add some debug logs to the getPipeLocation to make it easier to debug the issue :3

XDG_RUNTIME_DIR is /run/user/1000/snap.intellij-idea-community
/run/user/1000/snap.intellij-idea-community/discord-ipc-0

I also switched the order of the unixPaths array, and... 🤔

TMPDIR is null
TMP is null
TEMP is null
XDG_RUNTIME_DIR is /run/user/1000/snap.intellij-idea-community
/run/user/1000/snap.intellij-idea-community/discord-ipc-0

Maybe I can set the environment variables, then the issue wouldn't happen, right? Maybe I made a fucky wucky on this Ubuntu installation (first time using Linux on a desktop 😛), but that wouldn't fix the issue since the XDG_RUNTIME_DIR exists, causing the loop to break early.

Also maybe this is happening because I'm running directly from IntelliJ IDEA

It seems like it's an ubuntu related thing.

It actually seems that snap sets the XDG_RUNTIME_DIR automatically for applications installed via snap. (and the tmp & others variables aren't automatically set... my IDEA installation was installed via snap)

Compiling the rich presence and running via the terminal works fine, so it is just an issue if you are running via IDEA itself.

Maybe adding an option to override the socket path when using client.connect()? I think XDG_RUNTIME_DIR is used if you install Discord via snap (in my case: I installed it directly from Discord's website) and you are running the rich presence client via the terminal, but I'm not sure.

you can probably just set that system property from earlier to the new temp dir

Installing IDEA via Jetbrains Toolbox fixed the issue.

Maybe adding a small note in the README that, if IDEA is installed via snap/Ubuntu App Store, it won't work/will require workarounds?

This seems very edge case and we won't be putting something in the readme, we will simply refer anyone having trouble to this issue.
Closing this now, thanks for help debugging!