Search in sources :

Example 1 with FileInfo

use of com.almightyalpaca.jetbrains.plugins.discord.data.FileInfo 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;
}
Also used : FileInfo(com.almightyalpaca.jetbrains.plugins.discord.data.FileInfo) ProjectInfo(com.almightyalpaca.jetbrains.plugins.discord.data.ProjectInfo) InstanceInfo(com.almightyalpaca.jetbrains.plugins.discord.data.InstanceInfo) DiscordRichPresence(club.minnced.discord.rpc.DiscordRichPresence) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DiscordRichPresence (club.minnced.discord.rpc.DiscordRichPresence)1 FileInfo (com.almightyalpaca.jetbrains.plugins.discord.data.FileInfo)1 InstanceInfo (com.almightyalpaca.jetbrains.plugins.discord.data.InstanceInfo)1 ProjectInfo (com.almightyalpaca.jetbrains.plugins.discord.data.ProjectInfo)1 Nullable (org.jetbrains.annotations.Nullable)1