Compare commits

..

No commits in common. "master" and "v1.0.0" have entirely different histories.

5 changed files with 9 additions and 89 deletions

View File

@ -6,11 +6,6 @@
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jitpack.io" />
<option name="name" value="jitpack.io" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
@ -22,4 +17,4 @@
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
</project>

13
pom.xml
View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.mrmelon54</groupId>
<artifactId>codesize</artifactId>
<version>1.0.1</version>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<java.version>17</java.version>
@ -52,12 +52,6 @@
</resource>
</resources>
</build>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.formdev</groupId>
@ -104,10 +98,5 @@
<artifactId>jiconfont-google_material_design_icons</artifactId>
<version>2.2.0.2</version>
</dependency>
<dependency>
<groupId>com.github.Vatuu</groupId>
<artifactId>discord-rpc</artifactId>
<version>1.6.2</version>
</dependency>
</dependencies>
</project>

View File

@ -1,22 +1,19 @@
package xyz.mrmelon54.codesize;
import net.arikia.dev.drpc.DiscordEventHandlers;
import net.arikia.dev.drpc.DiscordRPC;
import net.arikia.dev.drpc.DiscordRichPresence;
import xyz.mrmelon54.codesize.components.InfoPanel;
import xyz.mrmelon54.codesize.enums.Theme;
import xyz.mrmelon54.codesize.ex.CannotCreateConfigFolderException;
import xyz.mrmelon54.codesize.process.FileFinder;
import xyz.mrmelon54.codesize.ui.PresetSelector;
import xyz.mrmelon54.codesize.utils.AboutDialog;
import xyz.mrmelon54.codesize.utils.ByteUtils;
import xyz.mrmelon54.codesize.utils.ComponentUtils;
import xyz.mrmelon54.codesize.utils.Settings;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
@ -24,8 +21,6 @@ import java.util.regex.Pattern;
public class CodeSize extends JFrame {
public final Settings settings;
private final Timer discordRpcTimer = new Timer(1000, e -> DiscordRPC.discordRunCallbacks());
private final long startTimestamp;
private JTextField pathField;
private JTextField regexField;
private InfoPanel infoPanel;
@ -34,15 +29,12 @@ public class CodeSize extends JFrame {
public CodeSize(Settings settings) {
super("Code Size");
this.settings = settings;
this.startTimestamp = System.currentTimeMillis();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setPreferredSize(new Dimension(800, 600));
setMinimumSize(new Dimension(800, 600));
setContentPane(createMainPanel());
setJMenuBar(createMenuBar());
Runtime.getRuntime().addShutdownHook(new Thread(this::shutdownRichPresence));
}
private JPanel createMainPanel() {
@ -93,15 +85,6 @@ public class CodeSize extends JFrame {
fileMenu.setMnemonic(KeyEvent.VK_F);
menuBar.add(fileMenu);
// Quit item
JMenuItem quitItem = fileMenu.add(new JMenuItem("Quit"));
quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK));
quitItem.addActionListener(e -> CodeSize.this.dispatchEvent(new WindowEvent(CodeSize.this, WindowEvent.WINDOW_CLOSING)));
// Tools menu
JMenu toolsMenu = menuBar.add(new JMenu("Tools"));
fileMenu.setMnemonic(KeyEvent.VK_T);
// Theme menu
JMenu themeMenu = new JMenu("Theme");
ButtonGroup bg = new ButtonGroup();
@ -120,21 +103,12 @@ public class CodeSize extends JFrame {
}
});
}
toolsMenu.add(themeMenu);
fileMenu.add(themeMenu);
JCheckBoxMenuItem richPresenceItem = new JCheckBoxMenuItem("Discord Rich Presence");
richPresenceItem.setSelected(settings.discordRichPresence);
richPresenceItem.addItemListener(e -> {
settings.discordRichPresence = richPresenceItem.isSelected();
tickRichPresence();
try {
settings.save();
} catch (IOException | CannotCreateConfigFolderException ex) {
System.out.println("Failed to save settings");
ex.printStackTrace();
}
});
toolsMenu.add(richPresenceItem);
// Quit item
JMenuItem quitItem = fileMenu.add(new JMenuItem("Quit"));
quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK));
quitItem.addActionListener(e -> CodeSize.this.dispatchEvent(new WindowEvent(CodeSize.this, WindowEvent.WINDOW_CLOSING)));
// Help menu
JMenu helpMenu = new JMenu("Help");
@ -149,7 +123,6 @@ public class CodeSize extends JFrame {
}
public void run() {
tickRichPresence();
setVisible(true);
}
@ -200,38 +173,6 @@ public class CodeSize extends JFrame {
FileFinder.search(mainFile, pattern, infoPanel);
infoPanel.finishLoading();
SwingUtilities.invokeLater(() -> searchButton.setEnabled(true));
updateRichPresence();
}).start();
}
private void tickRichPresence() {
if (settings.discordRichPresence) {
if (!discordRpcTimer.isRunning()) {
DiscordEventHandlers handlers = new DiscordEventHandlers.Builder().setReadyEventHandler(discordUser -> System.out.println("Welcome " + discordUser.username + "#" + discordUser.discriminator)).build();
DiscordRPC.discordInitialize("973597639339831356", handlers, true);
discordRpcTimer.start();
updateRichPresence();
}
} else shutdownRichPresence();
}
private void shutdownRichPresence() {
if (discordRpcTimer.isRunning()) {
discordRpcTimer.stop();
DiscordRPC.discordShutdown();
}
}
private void updateRichPresence() {
DiscordRichPresence discordRichPresence = new DiscordRichPresence();
long totalSize = (long) infoPanel.totalSize.getValue();
long totalLines = (long) infoPanel.totalLines.getValue();
if (totalSize == 0 && totalLines == 0) discordRichPresence.details = "No project data loaded..";
else {
discordRichPresence.details = "Total size: " + ByteUtils.ToBytesCount(totalSize);
discordRichPresence.state = "Total lines: " + totalLines;
}
discordRichPresence.startTimestamp = startTimestamp;
DiscordRPC.discordUpdatePresence(discordRichPresence);
}
}

View File

@ -144,10 +144,6 @@ public class InfoPanel extends JPanel {
public void setValue(float v) {
value = v;
}
public float getValue() {
return value;
}
}
public record InfoPanelFile(File file, long lines, long size) {

View File

@ -16,7 +16,6 @@ public class Settings {
private static final BuiltinPresets builtinPresets = new BuiltinPresets();
public Theme theme;
public boolean discordRichPresence;
public Vector<Preset> presets;
public Settings() {