JnCrMx / discord-game-sdk4j

Java bindings for Discord's Game SDK
MIT License
121 stars 23 forks source link

Add check, if a connection to Discord is available #80

Closed letorbi closed 5 months ago

letorbi commented 7 months ago

This PR introduces a new core method isDiscordRunning() as suggested in #76. The method throws a runtime exception, if a connection to Discord is not available.

The connection check itself is implemented in the classes UnixDiscordChannel and WindowsDiscordChannel. A new method isAvailable() has been added to both classes for this purpose. The method will return true, if the socket/pipe file exists and the channel is connected/open.

The general idea is that the implementing app calls isDiscordRunning() regularly to check whether Discord is still available or not. It lays within the responsibility of the app to handle exceptions. Typically the currently active core should be destroyed as soon as Discord is not running anymore and a new core should be created when Discord is running again.

An example implementation can be found in the main class of the Discord Rich Presence tool for Processing

The code for the Unix channel has has been tested under Linux, but the Windows functionality still needs to be tested.

letorbi commented 6 months ago

@JnCrMx What do you think about this PR? Is this the way to go or would you prefer another one?

JnCrMx commented 5 months ago

I'd be happy to merge this, I just have to test the Windows functionality first.

I'm not spending much time on Windows recently, but I'll try to test it this weekend.

Overall, I'm not 100% happy with the current approach to reconnecting, but that's not really related to this PR. I'd love to implement an option for automatic reconnects and I think this PR creates a good foundation for that.

letorbi commented 5 months ago

Thanks for the feedback :) I have just tested the PR on Windows and everything works as expected.

JnCrMx commented 5 months ago

Thank you :D