Skip to content

Commit ef95e4f

Browse files
committed
Check if JavaFX is installed, Check if OS is compatible
1 parent 9579beb commit ef95e4f

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

src/main/java/blobsaver/Main.java

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package blobsaver;
22

3+
import com.sun.javafx.PlatformUtil;
34
import javafx.application.Application;
45
import javafx.fxml.FXMLLoader;
56
import javafx.scene.Parent;
@@ -8,24 +9,46 @@
89

910
import java.io.IOException;
1011

11-
public class Main extends Application {
12+
public class Main {
1213

1314
static final String appVersion = "v1.2";
1415
static Stage primaryStage;
1516

1617
public static void main(String[] args) {
17-
launch(args);
18+
try {
19+
Class.forName("javafx.application.Application");
20+
if (PlatformUtil.isMac() || PlatformUtil.isWindows() || PlatformUtil.isLinux()) {
21+
JavaFxApplication.launchit(args);
22+
} else {
23+
int result = javax.swing.JOptionPane.showOptionDialog(null, "Cannot detect the OS. Assuming it is Linux. Continue?",
24+
"Warning", javax.swing.JOptionPane.OK_CANCEL_OPTION, javax.swing.JOptionPane.WARNING_MESSAGE, null, null, null);
25+
if (result == javax.swing.JOptionPane.CANCEL_OPTION) {
26+
System.exit(0);
27+
}
28+
JavaFxApplication.launchit(args);
29+
}
30+
} catch (ClassNotFoundException e) {
31+
javax.swing.JOptionPane.showMessageDialog(null, "JavaFX is not installed. Either install Oracle Java or\nif you are using OpenJRE/OpenJDK, install openjfx.\nOn Linux, use sudo apt-get install openjfx", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
32+
System.exit(-1);
33+
}
1834
}
1935

20-
@Override
21-
public void start(Stage primaryStage) throws IOException {
22-
Main.primaryStage = primaryStage;
23-
Parent root = FXMLLoader.load(getClass().getResource("blobsaver.fxml"));
24-
primaryStage.setTitle("SHSH Blob Saver " + appVersion);
25-
primaryStage.setScene(new Scene(root));
26-
primaryStage.getScene().getStylesheets().add(getClass().getResource("app.css").toExternalForm());
27-
primaryStage.show();
28-
primaryStage.setResizable(false);
29-
Controller.setPresetButtonNames();
36+
public static class JavaFxApplication extends Application {
37+
38+
static void launchit(String[] args) {
39+
launch(args);
40+
}
41+
42+
@Override
43+
public void start(Stage primaryStage) throws IOException {
44+
Main.primaryStage = primaryStage;
45+
Parent root = FXMLLoader.load(getClass().getResource("blobsaver.fxml"));
46+
primaryStage.setTitle("SHSH Blob Saver " + Main.appVersion);
47+
primaryStage.setScene(new Scene(root));
48+
primaryStage.getScene().getStylesheets().add(getClass().getResource("app.css").toExternalForm());
49+
primaryStage.show();
50+
primaryStage.setResizable(false);
51+
Controller.setPresetButtonNames();
52+
}
3053
}
31-
}
54+
}

0 commit comments

Comments
 (0)