use of club.minnced.discord.rpc.DiscordEventHandlers in project Intellij-Discord-Integration by Almighty-Alpaca.
the class DiscordIntegrationApplicationComponent method checkRpcConnection.
private void checkRpcConnection(@Nullable PresenceRenderContext renderContext) {
synchronized (rpcLock) {
LOG.trace("DiscordIntegrationApplicationComponent#checkRpcConnection()");
if (this.data == null || this.instanceInfo == null)
return;
Map<String, InstanceInfo> instances = this.data.getInstances();
boolean rpcConnectionExists;
// noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (instances) {
rpcConnectionExists = instances.values().stream().anyMatch(InstanceInfo::isHasRpcConnection);
}
LOG.trace("DiscordIntegrationApplicationComponent#checkRpcConnection()#instanceInfo.isHasRpcConnection() = {}", instanceInfo.isHasRpcConnection());
if (instanceInfo.isHasRpcConnection() && (renderContext == null ? renderContext = new PresenceRenderContext(data) : renderContext).isEmpty()) {
this.data.instanceSetHasRpcConnection(System.currentTimeMillis(), instanceInfo, false);
RPC.dispose();
} else // @formatter:off
if (!rpcConnectionExists && !instanceInfo.isHasRpcConnection() && this.channel != null && Objects.equals(channel.getView().getCoord(), this.channel.getAddress()) && !(renderContext == null ? new PresenceRenderContext(data) : renderContext).isEmpty()) // @formatter:on
{
this.data.instanceSetHasRpcConnection(System.currentTimeMillis(), instanceInfo, true);
new Thread(() -> {
DiscordEventHandlers handlers = new DiscordEventHandlers();
handlers.ready = this::rpcReady;
handlers.errored = this::rpcError;
handlers.disconnected = this::rpcDisconnected;
RPC.init(handlers, CLIENT_ID, () -> new PresenceRenderContext(this.data), new PresenceRenderer(), this::presenceUpdated);
}, "JetbrainsDiscordIntegration-RPC-Starter").start();
}
}
}
Aggregations