Skip to content

Commit

Permalink
Make UI work in headless mode
Browse files Browse the repository at this point in the history
Update comment in core main
  • Loading branch information
SamCarlberg committed Nov 4, 2016
1 parent eeb2024 commit 51a667d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
8 changes: 4 additions & 4 deletions core/src/main/java/edu/wpi/grip/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public void start(String[] args) throws IOException, InterruptedException {
}
}

// This will thrown an exception if the port specified by the save file is already taken.
// Since we have to have the server running to handle remotely loading pipelines and uploading
// images, as well as potential HTTP publishing operations, this will cause the program
// to exit.
// This will throw an exception if the port specified by the save file or command line
// argument is already taken. Since we have to have the server running to handle remotely
// loading pipelines and uploading images, as well as potential HTTP publishing operations,
// this will cause the program to exit.
gripServer.start();

if (pipelineRunner.state() == Service.State.NEW) {
Expand Down
64 changes: 35 additions & 29 deletions ui/src/main/java/edu/wpi/grip/ui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public void init() throws IOException {

notifyPreloader(new Preloader.ProgressNotification(0.45));
server.addHandler(pipelineSwitcher);
server.start();
notifyPreloader(new Preloader.ProgressNotification(0.6));

pipelineRunner.startAsync();
Expand All @@ -109,6 +108,41 @@ public void init() throws IOException {

@Override
public void start(Stage stage) throws IOException {
// If there was a file specified on the command line, open it immediately
if (parsedArgs.hasOption(CoreCommandLineHelper.FILE_OPTION)) {
String file = parsedArgs.getOptionValue(CoreCommandLineHelper.FILE_OPTION);
try {
project.open(new File(file));
} catch (IOException e) {
logger.log(Level.SEVERE, "Error loading file: " + file);
throw e;
}
}

// Set the port AFTER loading the project to override the setting in the file
if (parsedArgs.hasOption(CoreCommandLineHelper.PORT_OPTION)) {
try {
int port = Integer.parseInt(parsedArgs.getOptionValue(CoreCommandLineHelper.PORT_OPTION));
if (port < 1024 || port > 65535) {
logger.warning("Not a valid port: " + port);
} else {
// Valid port; set it (Note: this doesn't check to see if the port is available)
logger.info("Running server on port " + port);
server.setPort(port);
}
} catch (NumberFormatException e) {
logger.warning(
"Not a valid port: " + parsedArgs.getOptionValue(CoreCommandLineHelper.PORT_OPTION));
}
}

// This will throw an exception if the port specified by the save file or command line
// argument is already taken. Since we have to have the server running to handle remotely
// loading pipelines and uploading images, as well as potential HTTP publishing operations,
// this will cause the program to exit.
server.start();

// Load UI elements if we're not in headless mode
if (!headless) {
root = FXMLLoader.load(Main.class.getResource("MainWindow.fxml"), null, null,
injector::getInstance);
Expand All @@ -118,34 +152,6 @@ public void start(Stage stage) throws IOException {
cvOperations.addOperations();
notifyPreloader(new Preloader.ProgressNotification(0.9));

// If there was a file specified on the command line, open it immediately
if (parsedArgs.hasOption(CoreCommandLineHelper.FILE_OPTION)) {
String file = parsedArgs.getOptionValue(CoreCommandLineHelper.FILE_OPTION);
try {
project.open(new File(file));
} catch (IOException e) {
logger.log(Level.SEVERE, "Error loading file: " + file);
throw e;
}
}

// Set the port AFTER loading the project to override the setting in the file
if (parsedArgs.hasOption(CoreCommandLineHelper.PORT_OPTION)) {
try {
int port = Integer.parseInt(parsedArgs.getOptionValue(CoreCommandLineHelper.PORT_OPTION));
if (port < 1024 || port > 65535) {
logger.warning("Not a valid port: " + port);
} else {
// Valid port; set it (Note: this doesn't check to see if the port is available)
logger.info("Running server on port " + port);
server.setPort(port);
}
} catch (NumberFormatException e) {
logger.warning(
"Not a valid port: " + parsedArgs.getOptionValue(CoreCommandLineHelper.PORT_OPTION));
}
}

project.addIsSaveDirtyConsumer(newValue -> {
if (newValue) {
Platform.runLater(() -> stage.setTitle(MAIN_TITLE + " | Edited"));
Expand Down

0 comments on commit 51a667d

Please sign in to comment.