use of com.almightyalpaca.jetbrains.plugins.discord.data.InstanceInfo in project Intellij-Discord-Integration by Almighty-Alpaca.
the class ToolsMenuDisableAnAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getData(PlatformDataKeys.PROJECT);
if (project == null)
return;
DiscordIntegrationApplicationComponent applicationComponent = DiscordIntegrationApplicationComponent.getInstance();
DiscordIntegrationProjectComponent projectComponent = DiscordIntegrationProjectComponent.getInstance(project);
InstanceInfo instanceInfo = applicationComponent.getInstanceInfo();
if (projectComponent != null) {
ProjectInfo projectInfo = projectComponent.getProjectInfo();
ProjectSettingsStorage settings = DiscordIntegrationProjectSettings.getInstance(project).getState();
settings.setEnabled(!settings.isEnabled());
applicationComponent.updateData(data -> data.projectSetSettings(System.currentTimeMillis(), instanceInfo, projectInfo, settings));
update(e);
DiscordIntegrationProjectConfigurable.getInstance(project).reset();
}
}
use of com.almightyalpaca.jetbrains.plugins.discord.data.InstanceInfo in project Intellij-Discord-Integration by Almighty-Alpaca.
the class DiscordIntegrationApplicationComponent method initComponent.
@Override
public synchronized void initComponent() {
try // Fixes problems that crashes JGroups if those two properties aren't properly set
{
Locale locale = Locale.getDefault();
if (System.getProperty("user.language") == null)
System.setProperty("user.language", locale.getLanguage());
if (System.getProperty("user.country") == null)
System.setProperty("user.country", locale.getCountry());
} catch (Exception e) {
e.printStackTrace();
}
try {
String props = "fast.xml";
LOG.trace("DiscordIntegrationApplicationComponent#initComponent()#props = {}", props);
JChannel channel = new JChannel(props);
channel.setReceiver(this);
this.channel = channel;
channel.connect("JetbrainsDiscordIntegration v" + JetbrainsDiscordIntegration.PROTOCOL_VERSION);
ReplicatedData data = new ReplicatedData(channel, this);
this.data = data;
this.instanceInfo = new InstanceInfo(channel.getAddressAsString(), ApplicationInfo.getInstance());
LOG.trace("DiscordIntegrationApplicationComponent#initComponent()#this.instanceInfo = {}", this.instanceInfo);
data.instanceAdd(System.currentTimeMillis(), this.instanceInfo);
RPC.updatePresence(2, TimeUnit.SECONDS);
} catch (Exception e) {
if (this.channel != null) {
this.channel.close();
this.channel = null;
}
if (this.data != null) {
this.data.close();
this.data = null;
}
RPC.dispose();
throw new RuntimeException(e);
}
MessageBus bus = ApplicationManager.getApplication().getMessageBus();
connection = bus.connect();
connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerListener());
connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener());
EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster();
multicaster.addDocumentListener(this.documentListener = new DocumentListener());
multicaster.addEditorMouseListener(this.editorMouseListener = new EditorMouseListener());
checkExperiementalWindowListener();
VirtualFileManager.getInstance().addVirtualFileListener(this.virtualFileListener = new VirtualFileListener());
}
use of com.almightyalpaca.jetbrains.plugins.discord.data.InstanceInfo in project Intellij-Discord-Integration by Almighty-Alpaca.
the class DiscordIntegrationApplicationComponent method presenceUpdated.
protected long presenceUpdated(@NotNull PresenceRenderContext renderContext) {
LOG.trace("DiscordIntegrationApplicationComponent#presenceUpdated({})", renderContext);
InstanceInfo instance = renderContext.getInstance();
checkRpcConnection(renderContext);
LOG.trace("DiscordIntegrationApplicationComponent#presenceUpdated()#instance = {}", instance);
LOG.trace("DiscordIntegrationApplicationComponent#presenceUpdated()#instance.getSettings().isHideAfterPeriodOfInactivity() = {}", instance != null && instance.getSettings().isHideAfterPeriodOfInactivity());
if (instance != null && instance.getSettings().isHideAfterPeriodOfInactivity()) {
long delay = TimeUnit.NANOSECONDS.convert(instance.getTimeAccessed() + instance.getSettings().getInactivityTimeout(TimeUnit.MILLISECONDS) - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
LOG.trace("DiscordIntegrationApplicationComponent#presenceUpdated()#instance.getTimeAccessed() = {}", instance.getTimeAccessed());
LOG.trace("DiscordIntegrationApplicationComponent#presenceUpdated()#instance.getSettings().getInactivityTimeout(TimeUnit.MILLISECONDS) = {}", instance.getSettings().getInactivityTimeout(TimeUnit.MILLISECONDS));
LOG.trace("DiscordIntegrationApplicationComponent#presenceUpdated()#System.currentTimeMillis() = {}", System.currentTimeMillis());
LOG.trace("DiscordIntegrationApplicationComponent#presenceUpdated()#delay = {}", delay);
return delay;
}
return Long.MAX_VALUE;
}
use of com.almightyalpaca.jetbrains.plugins.discord.data.InstanceInfo 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 com.almightyalpaca.jetbrains.plugins.discord.data.InstanceInfo in project Intellij-Discord-Integration by Almighty-Alpaca.
the class DiscordIntegrationProjectConfigurable method apply.
@Override
public void apply() {
if (this.panel != null) {
this.panel.apply();
InstanceInfo instance = this.applicationComponent.getInstanceInfo();
DiscordIntegrationProjectComponent component = DiscordIntegrationProjectComponent.getInstance(this.settingsProviderProject.getProject());
if (component != null) {
ProjectInfo project = component.getProjectInfo();
this.applicationComponent.updateData(data -> data.instanceSetSettings(System.currentTimeMillis(), instance, this.settingsProviderApplication.getSettings()));
this.applicationComponent.updateData(data -> data.projectSetSettings(System.currentTimeMillis(), instance, project, this.settingsProviderProject.getSettings()));
this.applicationComponent.checkExperiementalWindowListener();
}
}
}
Aggregations