Skip to content

Commit 0cf73f1

Browse files
committed
Added client prerequisite check
Signed-off-by: Mitch Gaffigan <mitch.gaffigan@comcast.net>
1 parent bfe3348 commit 0cf73f1

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: Mitch Gaffigan <mitch@gaffigan.net>
3+
4+
package com.mirth.connect.client.ui;
5+
6+
/** Utility class to check if the client prerequisites are met. */
7+
public class ClientPrerequisites {
8+
9+
private ClientPrerequisites() {
10+
}
11+
12+
/** Checks if the client prerequisites are met. */
13+
public static String getMissing() {
14+
// Can't meaningfully check for Java 17 since the entrypoint is compiled with
15+
// class file version 61, which will fail to load on Java 8.
16+
if (!hasJavaFx()) {
17+
return "JavaFX";
18+
}
19+
20+
return null;
21+
}
22+
23+
private static boolean hasJavaFx() {
24+
// Use JPMS to check for JavaFX - the classes are on the classpath
25+
// even in Java SE, but the module will not be present except in FX
26+
return ModuleLayer.boot().findModule("javafx.graphics").isPresent();
27+
}
28+
}

client/src/com/mirth/connect/client/ui/Mirth.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import javax.imageio.ImageIO;
1414
import javax.swing.ImageIcon;
1515
import javax.swing.InputMap;
16+
import javax.swing.JOptionPane;
1617
import javax.swing.KeyStroke;
1718
import javax.swing.SwingUtilities;
1819
import javax.swing.ToolTipManager;
@@ -253,6 +254,13 @@ public static void initUIManager() {
253254
* String[]
254255
*/
255256
public static void main(String[] args) {
257+
var missingPrerequisite = ClientPrerequisites.getMissing();
258+
if (missingPrerequisite != null) {
259+
showUnsupportedJreDialog(missingPrerequisite);
260+
System.exit(1);
261+
return;
262+
}
263+
256264
CommandLineOptions opts = new CommandLineOptions(args);
257265

258266
if (StringUtils.isNotBlank(opts.getProtocols())) {
@@ -267,6 +275,18 @@ public static void main(String[] args) {
267275
start(opts.getServer(), opts.getVersion(), opts.getUsername(), opts.getPassword());
268276
}
269277

278+
private static void showUnsupportedJreDialog(String missingPrerequisite) {
279+
var message = String.format(
280+
"%s Client requires %s%nPlease relaunch the client with a supported JRE.",
281+
BrandingConstants.PRODUCT_NAME, missingPrerequisite);
282+
283+
try {
284+
JOptionPane.showMessageDialog(null, message, "Unsupported Java Runtime", JOptionPane.ERROR_MESSAGE);
285+
} catch (Throwable t) {
286+
System.err.println(message);
287+
}
288+
}
289+
270290
private static void start(final String server, final String version, final String username, final String password) {
271291
// disable the velocity logging
272292
Logger velocityLogger = LogManager.getLogger(RuntimeConstants.DEFAULT_RUNTIME_LOG_NAME);

0 commit comments

Comments
 (0)