Replace JOptionPane's with TinyFD to fix some Mac issues

This commit is contained in:
James Seibel
2024-10-15 07:43:13 -05:00
parent 69a5fdc720
commit 82e1587c4e
5 changed files with 29 additions and 19 deletions
@@ -115,19 +115,21 @@ public class Initializer
throw new RuntimeException(e);
}
if (MC_CLIENT != null)
{
// attempt to set up Swing so we can display dialogs (popup windows)
System.setProperty("java.awt.headless", "false");
if (GraphicsEnvironment.isHeadless())
{
LOGGER.warn("Java.awt.headless is false. This means Distant Horizons can't display error and info dialog windows.");
}
else
{
LOGGER.info("Java.awt.headless set to true. Distant Horizons can correctly display error and info dialog windows.");
}
}
// This code has been disabled since it can cause Mac
// to lock up and refuse the load (there's a bug with Java.awt texture loading)
//if (MC_CLIENT != null)
//{
// // attempt to set up Swing so we can display dialogs (popup windows)
// System.setProperty("java.awt.headless", "false");
// if (GraphicsEnvironment.isHeadless())
// {
// LOGGER.warn("Java.awt.headless is false. This means Distant Horizons can't display error and info dialog windows.");
// }
// else
// {
// LOGGER.info("Java.awt.headless set to true. Distant Horizons can correctly display error and info dialog windows.");
// }
//}
// link Core's config to the API
DhApi.Delayed.configs = DhApiConfig.INSTANCE;
@@ -37,6 +37,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftCli
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
import com.seibel.distanthorizons.coreapi.ModInfo;
import org.apache.logging.log4j.Logger;
import org.lwjgl.util.tinyfd.TinyFileDialogs;
import javax.swing.*;
import java.awt.*;
@@ -1098,7 +1099,9 @@ public class Config
{
if (!GraphicsEnvironment.isHeadless())
{
JOptionPane.showMessageDialog(null, "Button pressed!", "UITester dialog", JOptionPane.INFORMATION_MESSAGE);
LOGGER.info("Attempting to show tinyfd message box...");
boolean buttonPress = TinyFileDialogs.tinyfd_messageBox("Button pressed!", "UITester dialog", "ok", "info", false);
LOGGER.info("dialog returned with ["+(buttonPress ? "TRUE" : "FALSE")+"]");
}
else
{
@@ -37,6 +37,9 @@ public class JavaScreenHandlerScreen extends AbstractScreen
static
{
// Note: this code can cause Mac
// to lock up and refuse the load (there's a bug with Java.awt texture loading)
// Needs to be called before any Swing code is called, otherwise
// Swing will get stuck thinking it's headless
System.setProperty("java.awt.headless", "false");
@@ -31,6 +31,7 @@ import com.seibel.distanthorizons.core.jar.installer.WebDownloader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.lwjgl.util.tinyfd.TinyFileDialogs;
import javax.swing.*;
import java.awt.*;
@@ -313,7 +314,7 @@ public class JarMain
installMod.addActionListener(e -> {
if (minecraftDirPop.getSelectedFile() == null)
{
JOptionPane.showMessageDialog(frame, "Please select your install directory", ModInfo.READABLE_NAME, JOptionPane.WARNING_MESSAGE);
TinyFileDialogs.tinyfd_messageBox(ModInfo.READABLE_NAME, "Please select your install directory", "ok", "warning", false);
return;
}
@@ -327,11 +328,11 @@ public class JarMain
ModInfo.NAME + "-" + ModrinthGetter.releaseNames.get(downloadID.get()) + ".jar"
).toFile());
JOptionPane.showMessageDialog(frame, "Installation done. \nYou can now close the installer", ModInfo.READABLE_NAME, JOptionPane.INFORMATION_MESSAGE);
TinyFileDialogs.tinyfd_messageBox(ModInfo.READABLE_NAME, "Installation done. \nYou can now close the installer", "ok", "info", false);
}
catch (Exception f)
{
JOptionPane.showMessageDialog(frame, "Download failed. Check your internet connection \nStacktrace: " + f.getMessage(), ModInfo.READABLE_NAME, JOptionPane.ERROR_MESSAGE);
TinyFileDialogs.tinyfd_messageBox(ModInfo.READABLE_NAME, "Download failed. Check your internet connection \nStacktrace: " + f.getMessage(), "error", "info", false);
}
});
frame.add(installMod);
@@ -33,6 +33,7 @@ import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.coreapi.util.StringUtil;
import com.seibel.distanthorizons.coreapi.util.jar.DeleteOnUnlock;
import org.apache.logging.log4j.Logger;
import org.lwjgl.util.tinyfd.TinyFileDialogs;
import javax.swing.*;
import java.awt.*;
@@ -223,7 +224,7 @@ public class SelfUpdater
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);
TinyFileDialogs.tinyfd_messageBox(ModInfo.READABLE_NAME, message, "ok", "info", false);
}
else
{
@@ -279,7 +280,7 @@ public class SelfUpdater
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);
TinyFileDialogs.tinyfd_messageBox(ModInfo.READABLE_NAME, message, "ok", "info", false);
}
else
{