mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2025-01-22 21:31:23 +01:00
Added buttons to upload the log and create ViaVersion dumps
This commit is contained in:
parent
eefa397f68
commit
ad3e34b369
@ -120,6 +120,7 @@ dependencies {
|
||||
exclude group: "io.netty", module: "netty-codec"
|
||||
exclude group: "io.netty", module: "netty-transport"
|
||||
}
|
||||
include "gs.mclo:api:3.0.1"
|
||||
}
|
||||
|
||||
blossom {
|
||||
|
@ -56,7 +56,7 @@ public class ConsoleHandler {
|
||||
if (command.equalsIgnoreCase("gc")) {
|
||||
System.gc();
|
||||
System.out.println("GC Done");
|
||||
} else if (command.equalsIgnoreCase("via")) {
|
||||
} else if (command.equalsIgnoreCase("via") || command.equalsIgnoreCase("viaversion")) {
|
||||
Via.getManager().getCommandHandler().onCommand(new ConsoleCommandSender(), args.getAsArray());
|
||||
} else if (command.equalsIgnoreCase("threaddump")) {
|
||||
System.out.println("Thread Dump:");
|
||||
|
@ -122,7 +122,7 @@ public class AccountsTab extends AUITab {
|
||||
JPopupMenu contextMenu = new JPopupMenu();
|
||||
{
|
||||
JMenuItem selectItem = new JMenuItem("Select account");
|
||||
selectItem.addActionListener(e -> {
|
||||
selectItem.addActionListener(event -> {
|
||||
int index = this.accountsList.getSelectedIndex();
|
||||
if (index != -1) this.markSelected(index);
|
||||
});
|
||||
@ -130,7 +130,7 @@ public class AccountsTab extends AUITab {
|
||||
}
|
||||
{
|
||||
JMenuItem removeItem = new JMenuItem("Remove");
|
||||
removeItem.addActionListener(e -> {
|
||||
removeItem.addActionListener(event -> {
|
||||
int index = this.accountsList.getSelectedIndex();
|
||||
if (index != -1) {
|
||||
String removedName = model.remove(index);
|
||||
@ -154,7 +154,7 @@ public class AccountsTab extends AUITab {
|
||||
}
|
||||
{
|
||||
JMenuItem moveUp = new JMenuItem("Move up ↑");
|
||||
moveUp.addActionListener(e -> {
|
||||
moveUp.addActionListener(event -> {
|
||||
int index = this.accountsList.getSelectedIndex();
|
||||
if (index != -1) this.moveUp(index);
|
||||
});
|
||||
@ -162,7 +162,7 @@ public class AccountsTab extends AUITab {
|
||||
}
|
||||
{
|
||||
JMenuItem moveDown = new JMenuItem("Move down ↓");
|
||||
moveDown.addActionListener(e -> {
|
||||
moveDown.addActionListener(event -> {
|
||||
int index = this.accountsList.getSelectedIndex();
|
||||
if (index != -1) this.moveDown(index);
|
||||
});
|
||||
|
@ -17,20 +17,32 @@
|
||||
*/
|
||||
package net.raphimc.viaproxy.ui.impl;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import gs.mclo.api.MclogsClient;
|
||||
import gs.mclo.api.response.UploadLogResponse;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.protocolhack.viaproxy.ConsoleCommandSender;
|
||||
import net.raphimc.viaproxy.saves.impl.UISave;
|
||||
import net.raphimc.viaproxy.ui.AUITab;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyUI;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
public class AdvancedTab extends AUITab {
|
||||
|
||||
|
||||
JSpinner bindPort;
|
||||
JTextField proxy;
|
||||
JCheckBox proxyOnlineMode;
|
||||
JCheckBox legacySkinLoading;
|
||||
JButton viaVersionDumpButton;
|
||||
JButton uploadLogsButton;
|
||||
|
||||
public AdvancedTab(final ViaProxyUI frame) {
|
||||
super(frame, "Advanced");
|
||||
@ -84,6 +96,77 @@ public class AdvancedTab extends AUITab {
|
||||
ViaProxy.saveManager.uiSave.loadCheckBox("legacy_skin_loading", this.legacySkinLoading);
|
||||
contentPane.add(this.legacySkinLoading);
|
||||
}
|
||||
{
|
||||
this.viaVersionDumpButton = new JButton("Create ViaVersion dump");
|
||||
this.viaVersionDumpButton.setBounds(10, 250, 225, 20);
|
||||
this.viaVersionDumpButton.addActionListener(event -> {
|
||||
try {
|
||||
this.viaVersionDumpButton.setEnabled(false);
|
||||
Via.getManager().getCommandHandler().getSubCommand("dump").execute(new ConsoleCommandSender() {
|
||||
private static final String DUMP_LINK_HOST = "https://dump.viaversion.com";
|
||||
|
||||
@Override
|
||||
public void sendMessage(String msg) {
|
||||
if (msg.contains(DUMP_LINK_HOST)) {
|
||||
final String url = msg.substring(msg.indexOf(DUMP_LINK_HOST));
|
||||
ViaProxy.ui.openURL(url);
|
||||
final StringSelection stringSelection = new StringSelection(url);
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, stringSelection);
|
||||
ViaProxy.ui.showInfo("Copied ViaVersion dump link to clipboard");
|
||||
} else {
|
||||
ViaProxy.ui.showError(msg.replaceAll("§.", ""));
|
||||
}
|
||||
}
|
||||
}, new String[0]);
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Failed to create ViaVersion dump", e);
|
||||
ViaProxy.ui.showError("The ViaVersion dump could not be created.");
|
||||
} finally {
|
||||
this.viaVersionDumpButton.setEnabled(true);
|
||||
}
|
||||
});
|
||||
this.viaVersionDumpButton.setEnabled(false);
|
||||
contentPane.add(this.viaVersionDumpButton);
|
||||
}
|
||||
{
|
||||
this.uploadLogsButton = new JButton("Upload latest.log");
|
||||
this.uploadLogsButton.setBounds(249, 250, 225, 20);
|
||||
this.uploadLogsButton.addActionListener(event -> {
|
||||
final org.apache.logging.log4j.core.Logger logger = (org.apache.logging.log4j.core.Logger) LogManager.getRootLogger();
|
||||
final RollingRandomAccessFileAppender fileAppender = (RollingRandomAccessFileAppender) logger.getAppenders().get("LatestFile");
|
||||
fileAppender.getManager().flush();
|
||||
final File logFile = new File(fileAppender.getFileName());
|
||||
|
||||
try {
|
||||
this.uploadLogsButton.setEnabled(false);
|
||||
final MclogsClient mclogsClient = new MclogsClient("ViaProxy", ViaProxy.VERSION);
|
||||
final UploadLogResponse apiResponse = mclogsClient.uploadLog(logFile.toPath());
|
||||
if (apiResponse.isSuccess()) {
|
||||
ViaProxy.ui.openURL(apiResponse.getUrl());
|
||||
final StringSelection selection = new StringSelection(apiResponse.getUrl());
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
|
||||
ViaProxy.ui.showInfo("<html>Uploaded log file to <a href=\"\">" + apiResponse.getUrl() + "</a> (copied to clipboard)</html>");
|
||||
} else {
|
||||
ViaProxy.ui.showError("The log file could not be uploaded: " + apiResponse.getError());
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
ViaProxy.ui.showError("The log file could not be found.");
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Failed to upload log file", e);
|
||||
ViaProxy.ui.showError("The log file could not be uploaded.");
|
||||
} finally {
|
||||
this.uploadLogsButton.setEnabled(true);
|
||||
}
|
||||
});
|
||||
contentPane.add(this.uploadLogsButton);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReady() {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
this.viaVersionDumpButton.setEnabled(true);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,7 +110,7 @@ public class GeneralTab extends AUITab {
|
||||
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
}
|
||||
});
|
||||
this.serverVersion.addActionListener(e -> {
|
||||
this.serverVersion.addActionListener(event -> {
|
||||
if (this.betaCraftAuth == null) return; // This is called when the JComboBox is created (before betaCraftAuth is set)
|
||||
if (!(this.serverVersion.getSelectedItem() instanceof VersionEnum)) return;
|
||||
if (((VersionEnum) this.serverVersion.getSelectedItem()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
|
||||
@ -154,7 +154,7 @@ public class GeneralTab extends AUITab {
|
||||
{
|
||||
this.stateButton = new JButton("Loading ViaProxy...");
|
||||
this.stateButton.setBounds(10, 250, 465, 20);
|
||||
this.stateButton.addActionListener(e -> {
|
||||
this.stateButton.addActionListener(event -> {
|
||||
if (this.stateButton.getText().equalsIgnoreCase("Start")) this.start();
|
||||
else if (this.stateButton.getText().equalsIgnoreCase("Stop")) this.stop();
|
||||
});
|
||||
|
@ -94,7 +94,7 @@ public class AddAccountPopup extends JDialog {
|
||||
{
|
||||
JButton copyCodeButton = new JButton("Copy Code");
|
||||
copyCodeButton.setBounds(this.getWidth() / 2 - 130 / 2, 130, 100, 20);
|
||||
copyCodeButton.addActionListener(e -> {
|
||||
copyCodeButton.addActionListener(event -> {
|
||||
StringSelection selection = new StringSelection(this.deviceCode.userCode());
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
|
||||
});
|
||||
|
@ -83,7 +83,7 @@ public class DownloadPopup extends JDialog {
|
||||
{
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
cancelButton.setBounds(10, 40, 365, 20);
|
||||
cancelButton.addActionListener(e -> this.close(false));
|
||||
cancelButton.addActionListener(event -> this.close(false));
|
||||
contentPane.add(cancelButton);
|
||||
}
|
||||
this.start();
|
||||
|
Loading…
Reference in New Issue
Block a user