Merge pull request #7441 from deathbeam/fix-discord-ja
Wrap DiscordEventHandlers in native lib try/catch
This commit is contained in:
@@ -47,18 +47,41 @@ import net.runelite.discord.DiscordUser;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class DiscordService implements AutoCloseable
|
public class DiscordService implements AutoCloseable
|
||||||
{
|
{
|
||||||
@Inject
|
private final EventBus eventBus;
|
||||||
private EventBus eventBus;
|
private final RuneLiteProperties runeLiteProperties;
|
||||||
|
private final ScheduledExecutorService executorService;
|
||||||
|
private final DiscordRPC discordRPC;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private RuneLiteProperties runeLiteProperties;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ScheduledExecutorService executorService;
|
|
||||||
|
|
||||||
private DiscordRPC discordRPC;
|
|
||||||
// Hold a reference to the event handlers to prevent the garbage collector from deleting them
|
// Hold a reference to the event handlers to prevent the garbage collector from deleting them
|
||||||
private final DiscordEventHandlers discordEventHandlers = new DiscordEventHandlers();
|
private final DiscordEventHandlers discordEventHandlers;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private DiscordService(
|
||||||
|
final EventBus eventBus,
|
||||||
|
final RuneLiteProperties runeLiteProperties,
|
||||||
|
final ScheduledExecutorService executorService)
|
||||||
|
{
|
||||||
|
|
||||||
|
this.eventBus = eventBus;
|
||||||
|
this.runeLiteProperties = runeLiteProperties;
|
||||||
|
this.executorService = executorService;
|
||||||
|
|
||||||
|
DiscordRPC discordRPC = null;
|
||||||
|
DiscordEventHandlers discordEventHandlers = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
discordRPC = DiscordRPC.INSTANCE;
|
||||||
|
discordEventHandlers = new DiscordEventHandlers();
|
||||||
|
}
|
||||||
|
catch (UnsatisfiedLinkError e)
|
||||||
|
{
|
||||||
|
log.warn("Failed to load Discord library, Discord support will be disabled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.discordRPC = discordRPC;
|
||||||
|
this.discordEventHandlers = discordEventHandlers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
@@ -67,18 +90,12 @@ public class DiscordService implements AutoCloseable
|
|||||||
*/
|
*/
|
||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
log.info("Initializing Discord RPC service.");
|
if (discordEventHandlers == null)
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
discordRPC = DiscordRPC.INSTANCE;
|
|
||||||
}
|
|
||||||
catch (UnsatisfiedLinkError e)
|
|
||||||
{
|
|
||||||
log.warn("Failed to load Discord library, Discord support will be disabled.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info("Initializing Discord RPC service.");
|
||||||
discordEventHandlers.ready = this::ready;
|
discordEventHandlers.ready = this::ready;
|
||||||
discordEventHandlers.disconnected = this::disconnected;
|
discordEventHandlers.disconnected = this::disconnected;
|
||||||
discordEventHandlers.errored = this::errored;
|
discordEventHandlers.errored = this::errored;
|
||||||
|
|||||||
Reference in New Issue
Block a user