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
|
@Inject
|
||||||
private ScheduledExecutorService executorService;
|
private ScheduledExecutorService executorService;
|
||||||
|
|
||||||
private final DiscordEventHandlers discordEventHandlers = new DiscordEventHandlers();
|
private DiscordRPC discordRPC;
|
||||||
private final DiscordRPC discordRPC = DiscordRPC.INSTANCE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the Discord service, sets up the event handlers and starts worker thread that will poll discord
|
* 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()
|
public void init()
|
||||||
{
|
{
|
||||||
log.info("Initializing Discord RPC service.");
|
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.ready = this::ready;
|
||||||
discordEventHandlers.disconnected = this::disconnected;
|
discordEventHandlers.disconnected = this::disconnected;
|
||||||
discordEventHandlers.errored = this::errored;
|
discordEventHandlers.errored = this::errored;
|
||||||
@@ -83,7 +94,10 @@ public class DiscordService implements AutoCloseable
|
|||||||
@Override
|
@Override
|
||||||
public void close()
|
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)
|
public void updatePresence(DiscordPresence discordPresence)
|
||||||
{
|
{
|
||||||
|
if (discordRPC == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final DiscordRichPresence discordRichPresence = new DiscordRichPresence();
|
final DiscordRichPresence discordRichPresence = new DiscordRichPresence();
|
||||||
discordRichPresence.state = discordPresence.getState();
|
discordRichPresence.state = discordPresence.getState();
|
||||||
discordRichPresence.details = discordPresence.getDetails();
|
discordRichPresence.details = discordPresence.getDetails();
|
||||||
@@ -127,7 +146,10 @@ public class DiscordService implements AutoCloseable
|
|||||||
*/
|
*/
|
||||||
public void clearPresence()
|
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)
|
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()
|
private void ready()
|
||||||
|
|||||||
Reference in New Issue
Block a user