Merge pull request #831 from deathbeam/do-not-fail-on-natives
Continue running in case Discord lib load failed
This commit is contained in:
@@ -55,8 +55,7 @@ public class DiscordService implements AutoCloseable
|
||||
@Inject
|
||||
private ScheduledExecutorService executorService;
|
||||
|
||||
private final DiscordEventHandlers discordEventHandlers = new DiscordEventHandlers();
|
||||
private final DiscordRPC discordRPC = DiscordRPC.INSTANCE;
|
||||
private DiscordRPC discordRPC;
|
||||
|
||||
/**
|
||||
* Initializes the Discord service, sets up the event handlers and starts worker thread that will poll discord
|
||||
@@ -66,6 +65,18 @@ public class DiscordService implements AutoCloseable
|
||||
public void init()
|
||||
{
|
||||
log.info("Initializing Discord RPC service.");
|
||||
|
||||
try
|
||||
{
|
||||
discordRPC = DiscordRPC.INSTANCE;
|
||||
}
|
||||
catch (UnsatisfiedLinkError e)
|
||||
{
|
||||
log.warn("Failed to load Discord library, Discord support will be disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
final DiscordEventHandlers discordEventHandlers = new DiscordEventHandlers();
|
||||
discordEventHandlers.ready = this::ready;
|
||||
discordEventHandlers.disconnected = this::disconnected;
|
||||
discordEventHandlers.errored = this::errored;
|
||||
@@ -82,9 +93,12 @@ public class DiscordService implements AutoCloseable
|
||||
*/
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
if (discordRPC != null)
|
||||
{
|
||||
discordRPC.Discord_Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the currently set presence of the logged in user.
|
||||
@@ -95,6 +109,11 @@ public class DiscordService implements AutoCloseable
|
||||
*/
|
||||
public void updatePresence(DiscordPresence discordPresence)
|
||||
{
|
||||
if (discordRPC == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final DiscordRichPresence discordRichPresence = new DiscordRichPresence();
|
||||
discordRichPresence.state = discordPresence.getState();
|
||||
discordRichPresence.details = discordPresence.getDetails();
|
||||
@@ -126,9 +145,12 @@ public class DiscordService implements AutoCloseable
|
||||
* Clears the currently set presence.
|
||||
*/
|
||||
public void clearPresence()
|
||||
{
|
||||
if (discordRPC != null)
|
||||
{
|
||||
discordRPC.Discord_ClearPresence();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds to the given user with the specified reply type.
|
||||
@@ -137,9 +159,12 @@ public class DiscordService implements AutoCloseable
|
||||
* @param reply The reply type
|
||||
*/
|
||||
public void respondToRequest(String userId, DiscordReplyType reply)
|
||||
{
|
||||
if (discordRPC != null)
|
||||
{
|
||||
discordRPC.Discord_Respond(userId, reply.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
private void ready()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user