55import com .google .common .eventbus .Subscribe ;
66import com .google .inject .Guice ;
77import com .google .inject .Injector ;
8+ import com .google .inject .util .Modules ;
89import com .sun .javafx .application .PlatformImpl ;
910import edu .wpi .grip .core .GRIPCoreModule ;
1011import edu .wpi .grip .core .PipelineRunner ;
@@ -37,8 +38,12 @@ public class Main extends Application {
3738 @ Inject private Project project ;
3839 @ Inject private Logger logger ;
3940
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+ */
4045 @ VisibleForTesting
41- protected final Injector injector = Guice . createInjector ( new GRIPCoreModule (), new GRIPUIModule ()) ;
46+ protected Injector injector ;
4247
4348 private final Object dialogLock = new Object ();
4449 private Parent root ;
@@ -47,23 +52,22 @@ public static void main(String[] args) {
4752 launch (args );
4853 }
4954
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-
5855 @ Override
5956 @ SuppressWarnings ("PMD.SignatureDeclareThrowsException" )
6057 public void start (Stage stage ) throws Exception {
61- // If --headless was specified on the command line, run in headless mode
6258 List <String > parameters = new ArrayList <>(getParameters ().getRaw ());
6359
6460 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+
6565 parameters .remove ("--headless" );
6666 } 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+
6771 root = FXMLLoader .load (Main .class .getResource ("MainWindow.fxml" ), null , null , injector ::getInstance );
6872 root .setStyle ("-fx-font-size: " + DPIUtility .FONT_SIZE + "px" );
6973
0 commit comments