5
5
import com.google.common.eventbus.Subscribe;
6
6
import com.google.inject.Guice;
7
7
import com.google.inject.Injector;
8
+ import com.google.inject.util.Modules;
8
9
import com.sun.javafx.application.PlatformImpl;
9
10
import edu.wpi.grip.core.GRIPCoreModule;
10
11
import edu.wpi.grip.core.PipelineRunner;
@@ -37,8 +38,12 @@ public class Main extends Application {
37
38
@Inject private Project project;
38
39
@Inject private Logger logger;
39
40
41
+ /**
42
+ * JavaFX insists on creating the main application with its own reflection code, so we can't create with the
43
+ * Guice and do automatic field injection. However, we can inject it after the fact.
44
+ */
40
45
@VisibleForTesting
41
- protected final Injector injector = Guice.createInjector(new GRIPCoreModule(), new GRIPUIModule()) ;
46
+ protected Injector injector;
42
47
43
48
private final Object dialogLock = new Object();
44
49
private Parent root;
@@ -47,23 +52,22 @@ public static void main(String[] args) {
47
52
launch(args);
48
53
}
49
54
50
- /**
51
- * JavaFX insists on creating the main application with its own reflection code, so we can't create with the
52
- * Guice and do automatic field injection. However, we can inject it after the fact.
53
- */
54
- public Main() {
55
- injector.injectMembers(this);
56
- }
57
-
58
55
@Override
59
56
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
60
57
public void start(Stage stage) throws Exception {
61
- // If --headless was specified on the command line, run in headless mode
62
58
List<String> parameters = new ArrayList<>(getParameters().getRaw());
63
59
64
60
if (parameters.contains("--headless")) {
61
+ // If --headless was specified on the command line, run in headless mode (only use the core module)
62
+ injector = Guice.createInjector(new GRIPCoreModule());
63
+ injector.injectMembers(this);
64
+
65
65
parameters.remove("--headless");
66
66
} else {
67
+ // Otherwise, run with both the core and UI modules, and show the JavaFX stage
68
+ injector = Guice.createInjector(Modules.override(new GRIPCoreModule()).with(new GRIPUIModule()));
69
+ injector.injectMembers(this);
70
+
67
71
root = FXMLLoader.load(Main.class.getResource("MainWindow.fxml"), null, null, injector::getInstance);
68
72
root.setStyle("-fx-font-size: " + DPIUtility.FONT_SIZE + "px");
69
73
0 commit comments