diff --git a/convex-gui/src/main/java/convex/gui/components/AbstractGUI.java b/convex-gui/src/main/java/convex/gui/components/AbstractGUI.java index df33f6c6e..acfa28928 100644 --- a/convex-gui/src/main/java/convex/gui/components/AbstractGUI.java +++ b/convex-gui/src/main/java/convex/gui/components/AbstractGUI.java @@ -5,7 +5,6 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; import javax.swing.JFrame; import javax.swing.JPanel; @@ -67,15 +66,8 @@ public void setupFrame(JFrame frame) { } public void waitForClose() { - try { - finished.get(); - close(); - } catch (ExecutionException e) { - // Probably won't happen? - } catch (InterruptedException e) { - // Set interrupt status, in case caller wants to handle this - Thread.currentThread().interrupt(); - } + finished.join(); + close(); } public JFrame getFrame() { diff --git a/convex-gui/src/main/java/convex/gui/utils/Toolkit.java b/convex-gui/src/main/java/convex/gui/utils/Toolkit.java index 8c5795b38..94c8be6ef 100644 --- a/convex-gui/src/main/java/convex/gui/utils/Toolkit.java +++ b/convex-gui/src/main/java/convex/gui/utils/Toolkit.java @@ -16,8 +16,11 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; +import java.io.Console; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -366,4 +369,21 @@ public static JComponent withTitledBorder(String title, JComponent comp) { public static Icon menuIcon(int codePoint) { return SymbolIcon.get(codePoint,Toolkit.BUTTON_FONT.getSize()); } + + public static boolean checkIfTerminal() { + Console c=System.console(); + // If null, we have no terminal (Java up to 21) + if (c==null) return false; + + // We have a console, but in Java 22+ we need to check if it is actually a terminal + try { + Method m=c.getClass().getMethod("isTerminal"); + return (Boolean)m.invoke(c); + } catch (NoSuchMethodException e) { + return true; + } catch (SecurityException | IllegalAccessException | InvocationTargetException e) { + // Shouldn't happen? + return false; + } + } } diff --git a/convex-integration/src/main/java/convex/main/Main.java b/convex-integration/src/main/java/convex/main/Main.java index 16ab5163f..aeae4e554 100644 --- a/convex-integration/src/main/java/convex/main/Main.java +++ b/convex-integration/src/main/java/convex/main/Main.java @@ -1,9 +1,12 @@ package convex.main; +import convex.gui.utils.Toolkit; + public class Main { public static void main(String... args) { - if (System.console()!=null) { + boolean terminal=Toolkit.checkIfTerminal(); + if (terminal) { convex.cli.Main.main(args); } else { convex.gui.MainGUI.main(args);