use of club.minnced.discord.rpc.DiscordRichPresence in project Mindustry by Anuken.
the class DesktopPlatform method updateRPC.
@Override
public void updateRPC() {
if (!useDiscord)
return;
DiscordRichPresence presence = new DiscordRichPresence();
if (!state.is(State.menu)) {
presence.state = Strings.capitalize(state.mode.name()) + ", Solo";
presence.details = Strings.capitalize(world.getMap().name) + " | Wave " + state.wave;
presence.largeImageText = "Wave " + state.wave;
if (Net.active()) {
presence.partyMax = 16;
presence.partySize = playerGroup.size();
presence.state = Strings.capitalize(state.mode.name());
}
} else {
if (ui.editor != null && ui.editor.isShown()) {
presence.state = "In Editor";
} else {
presence.state = "In Menu";
}
}
presence.largeImageKey = "logo";
DiscordRPC.INSTANCE.Discord_UpdatePresence(presence);
}
use of club.minnced.discord.rpc.DiscordRichPresence in project Intellij-Discord-Integration by Almighty-Alpaca.
the class PresenceRenderer method apply.
@Nullable
@Override
public DiscordRichPresence apply(@NotNull PresenceRenderContext context) {
LOG.trace("DiscordRichPresence#apply({})", context);
if (context.isEmpty())
return null;
InstanceInfo instance = context.getInstance();
ProjectInfo project = context.getProject();
FileInfo file = context.getFile();
DiscordRichPresence presence = new DiscordRichPresence();
if (instance != null) {
InstanceInfo.DistributionInfo distribution = instance.getDistribution();
if (project != null) {
presence.details = "Working on " + project.getName();
presence.startTimestamp = project.getTimeOpened() / 1000;
if (project.getSettings().getDescription() != null) {
presence.state = project.getSettings().getDescription();
} else if (file != null && instance.getSettings().isShowFiles()) {
presence.state = (file.isReadOnly() && instance.getSettings().isShowReadingInsteadOfWriting() ? "Reading " : "Editing ") + (instance.getSettings().isShowFileExtensions() ? file.getName() : file.getBaseName());
presence.largeImageKey = file.getAssetName(instance.getSettings().isShowUnknownImageFile()) + "-large";
presence.largeImageText = file.getLanguageName();
presence.smallImageKey = distribution.getAssetName(instance.getSettings().isShowUnknownImageIDE()) + "-small";
presence.smallImageText = "Using " + distribution.getName() + " version " + distribution.getVersion();
}
}
if (presence.largeImageKey == null || presence.largeImageKey.equals("none-large")) {
presence.largeImageKey = distribution.getAssetName(instance.getSettings().isShowUnknownImageIDE()) + "-large";
presence.largeImageText = "Using " + distribution.getName() + " version " + distribution.getVersion();
presence.smallImageKey = null;
presence.smallImageText = null;
}
}
return presence;
}
use of club.minnced.discord.rpc.DiscordRichPresence in project Intellij-Discord-Integration by Almighty-Alpaca.
the class RPC method init.
public static synchronized void init(@NotNull DiscordEventHandlers handlers, @NotNull String clientId, @NotNull Supplier<PresenceRenderContext> contextSupplier, @NotNull Function<PresenceRenderContext, DiscordRichPresence> renderer, @NotNull ToLongFunction<PresenceRenderContext> changeCallback) {
LOG.trace("RPC.init({}, {}, {}, {})", "DiscordEventHandler", clientId, contextSupplier, renderer);
if (!RPC.initialized) {
RPC.initialized = true;
DiscordRPC.INSTANCE.Discord_Initialize(clientId, handlers, false, null);
RPC.updatePresence(1, TimeUnit.SECONDS);
if (callbackRunner == null) {
RPC.callbackRunner = new Thread(() -> {
while (RPC.initialized) {
try {
DiscordRPC.INSTANCE.Discord_RunCallbacks();
LockSupport.parkNanos(2_000_000);
} catch (Exception e) {
if (!(e instanceof InterruptedException))
LOG.warn("An error occurred in RPC.callbackRunner", e);
}
}
RPC.callbackRunner = null;
}, "JetbrainsDiscordIntegration-RPC-Callback-Handler");
RPC.callbackRunner.start();
}
if (RPC.initialized) {
RPC.delayedPresenceRunner = new Thread(() -> {
while (!Thread.currentThread().isInterrupted()) {
try {
long timeout = RPC.nextPresenceUpdate - System.nanoTime();
LOG.trace("RPC.delayedPresenceRunner$run#timeout~1 = {}ns", timeout);
if (timeout <= 0) {
PresenceRenderContext renderContext = contextSupplier.get();
DiscordRichPresence newPresence = renderer.apply(renderContext);
if (newPresence == null)
newPresence = new DiscordRichPresence();
final DiscordRichPresence finalNewPresence = newPresence;
LOG.trace("RPC.delayedPresenceRunner$run#newPresence = {}", Logger.LazyString.create(() -> GSON.toJson(finalNewPresence)));
if (!Objects.equals(RPC.presence, newPresence)) {
DiscordRPC.INSTANCE.Discord_UpdatePresence(newPresence);
RPC.presence = newPresence;
}
timeout = changeCallback.applyAsLong(renderContext);
}
long newTimeout = RPC.nextPresenceUpdate - System.nanoTime();
if (newTimeout < 0)
newTimeout = Long.MAX_VALUE;
timeout = Long.min(timeout, newTimeout);
LOG.trace("RPC.delayedPresenceRunner$run#timeout~2 = {}ns", timeout);
if (timeout > 0)
LockSupport.parkNanos(timeout);
else
LockSupport.park();
} catch (Exception e) {
if (!(e instanceof InterruptedException))
LOG.error("An error occurred in RPC.delayedPresenceRunner", e);
}
}
RPC.delayedPresenceRunner = null;
}, "JetbrainsDiscordIntegration-RPC-Delayed-Presence-Handler");
RPC.delayedPresenceRunner.start();
}
}
}
Aggregations