Merge pull request #831 from deathbeam/do-not-fail-on-natives

Continue running in case Discord lib load failed
This commit is contained in:
Adam
2018-03-05 09:12:22 -05:00
committed by GitHub

View File

@@ -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;
@@ -83,7 +94,10 @@ public class DiscordService implements AutoCloseable
@Override
public void close()
{
discordRPC.Discord_Shutdown();
if (discordRPC != null)
{
discordRPC.Discord_Shutdown();
}
}
/**
@@ -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();
@@ -127,7 +146,10 @@ public class DiscordService implements AutoCloseable
*/
public void clearPresence()
{
discordRPC.Discord_ClearPresence();
if (discordRPC != null)
{
discordRPC.Discord_ClearPresence();
}
}
/**
@@ -138,7 +160,10 @@ public class DiscordService implements AutoCloseable
*/
public void respondToRequest(String userId, DiscordReplyType reply)
{
discordRPC.Discord_Respond(userId, reply.ordinal());
if (discordRPC != null)
{
discordRPC.Discord_Respond(userId, reply.ordinal());
}
}
private void ready()