Fix potential issues when java.awt.headless is true

This commit is contained in:
James Seibel
2024-03-24 11:52:32 -05:00
parent 63b6365128
commit bbe5ae9b7c
2 changed files with 39 additions and 10 deletions
@@ -37,7 +37,9 @@ import com.seibel.distanthorizons.coreapi.util.StringUtil;
import org.apache.logging.log4j.Logger;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.util.List;
/**
@@ -1423,10 +1425,20 @@ public class Config
.set(new HashMap<String, String>())
.build();
public static ConfigUIButton uiButtonTest = new ConfigUIButton(() -> { new Thread(() -> {
System.setProperty("java.awt.headless", "false"); // Required to make it work
JOptionPane.showMessageDialog(null, "Button pressed!", "UITester dialog", JOptionPane.INFORMATION_MESSAGE);
});});
public static ConfigUIButton uiButtonTest = new ConfigUIButton(() ->
{
new Thread(() ->
{
if (!GraphicsEnvironment.isHeadless())
{
JOptionPane.showMessageDialog(null, "Button pressed!", "UITester dialog", JOptionPane.INFORMATION_MESSAGE);
}
else
{
LOGGER.info("button pressed!");
}
});
});
public static ConfigCategory categoryTest = new ConfigCategory.Builder().set(CategoryTest.class).build();
@@ -33,6 +33,7 @@ import com.seibel.distanthorizons.coreapi.util.jar.DeleteOnUnlock;
import org.apache.logging.log4j.Logger;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.net.URLEncoder;
import java.nio.file.Files;
@@ -222,9 +223,17 @@ public class SelfUpdater
deleteOldJarOnJvmShutdown = true;
LOGGER.info(ModInfo.READABLE_NAME + " successfully updated. It will apply on game's relaunch");
new Thread(() -> {
System.setProperty("java.awt.headless", "false"); // Required to make it work
JOptionPane.showMessageDialog(null, ModInfo.READABLE_NAME + " updated, this will be applied on game restart.", ModInfo.READABLE_NAME, JOptionPane.INFORMATION_MESSAGE);
new Thread(() ->
{
String message = ModInfo.READABLE_NAME + " updated, this will be applied on game restart.";
if (!GraphicsEnvironment.isHeadless())
{
JOptionPane.showMessageDialog(null, message, ModInfo.READABLE_NAME, JOptionPane.INFORMATION_MESSAGE);
}
else
{
LOGGER.info(message);
}
}).start();
return true;
}
@@ -270,9 +279,17 @@ public class SelfUpdater
deleteOldJarOnJvmShutdown = true;
LOGGER.info(ModInfo.READABLE_NAME + " successfully updated. It will apply on game's relaunch");
new Thread(() -> {
System.setProperty("java.awt.headless", "false"); // Required to make it work
JOptionPane.showMessageDialog(null, ModInfo.READABLE_NAME + " updated, this will be applied on game restart.", ModInfo.READABLE_NAME, JOptionPane.INFORMATION_MESSAGE);
new Thread(() ->
{
String message = ModInfo.READABLE_NAME + " updated, this will be applied on game restart.";
if (!GraphicsEnvironment.isHeadless())
{
JOptionPane.showMessageDialog(null, message, ModInfo.READABLE_NAME, JOptionPane.INFORMATION_MESSAGE);
}
else
{
LOGGER.info(message);
}
}).start();
zis.close();