Search in sources :

Example 1 with PresenceRenderer

use of com.almightyalpaca.jetbrains.plugins.discord.presence.PresenceRenderer 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();
        }
    }
}
Also used : PresenceRenderContext(com.almightyalpaca.jetbrains.plugins.discord.presence.PresenceRenderContext) PresenceRenderer(com.almightyalpaca.jetbrains.plugins.discord.presence.PresenceRenderer) InstanceInfo(com.almightyalpaca.jetbrains.plugins.discord.data.InstanceInfo) DiscordEventHandlers(club.minnced.discord.rpc.DiscordEventHandlers)

Aggregations

DiscordEventHandlers (club.minnced.discord.rpc.DiscordEventHandlers)1 InstanceInfo (com.almightyalpaca.jetbrains.plugins.discord.data.InstanceInfo)1 PresenceRenderContext (com.almightyalpaca.jetbrains.plugins.discord.presence.PresenceRenderContext)1 PresenceRenderer (com.almightyalpaca.jetbrains.plugins.discord.presence.PresenceRenderer)1