Closed letorbi closed 5 months ago
@JnCrMx What do you think about this PR? Is this the way to go or would you prefer another one?
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.
Thanks for the feedback :) I have just tested the PR on Windows and everything works as expected.
Thank you :D
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
andWindowsDiscordChannel
. A new methodisAvailable()
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.