Compare commits

..

No commits in common. "bf754c79d6e30a6fa36046d8f8abc6c9eced0151" and "392d10c58729f23e9546c6dbc2249186dd053754" have entirely different histories.

4 changed files with 37 additions and 23 deletions

View File

@ -27,7 +27,8 @@ public class LinuxScheduler {
try {
String taskName = "numbers-station-main_" + settings.getName();
Process listProcess = new ProcessBuilder("crontab", "-l").start();
// TODO: assume it's on the PATH
Process listProcess = new ProcessBuilder("/usr/bin/crontab", "-l").start();
if (!listProcess.waitFor(5, TimeUnit.SECONDS)) {
String message = "Failed to query " + taskName + " task: process timed out";
logger.log(Level.SEVERE, message);
@ -68,7 +69,8 @@ public class LinuxScheduler {
String newCrontab = sb.toString();
Process addProcess = new ProcessBuilder("crontab", "-").start();
// TODO: assume it's on the PATH
Process addProcess = new ProcessBuilder("/usr/bin/crontab", "-").start();
Writer w = new OutputStreamWriter(addProcess.getOutputStream(), "UTF-8");
System.out.println(newCrontab);
w.write(newCrontab);
@ -92,6 +94,23 @@ public class LinuxScheduler {
return Results.failure(message);
}
// Path cronDPath = Paths.get("/etc/cron.d");
// if (!Files.exists(cronDPath)) {
// String message = "/etc/cron.d does not exist, cannot create cron entry. Select 'Manage schedule externally' and set up scheduling as desired.";
// logger.log(Level.SEVERE, message);
// return Results.failure(message);
// }
// Path cronPath = cronDPath.resolve(settings.safeName());
// try {
// Files.write(cronPath, cronEntry(settings).getBytes(StandardCharsets.UTF_8));
// } catch (Exception e) {
// String message = "Failed to write cron file at '" + cronPath.toString() + "'";
// logger.log(Level.SEVERE, message, e);
// return Results.failure(message);
// }
return Results.success(true);
}

View File

@ -181,26 +181,22 @@ public class MainController implements Initializable {
stationNameField.textProperty().bindBidirectional(selectedStationName);
nextSendTimeLabel.textProperty().bind(nextSendTime);
nextSendTime.set("sup brah");
Result<MainSettings, Exception> result = MainSettings.load();
if (!result.hasSuccess()) {
Alert alert = new Alert(Alert.AlertType.ERROR, "Unable to load settings file. See log for details. Reinitialize settings? This may overwrite existing settings.", ButtonType.YES, ButtonType.NO);
// TODO: on failure, prompt user to re-initialize settings
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Settings load error");
alert.setHeaderText(null);
Optional<ButtonType> promptResult = alert.showAndWait();
alert.setContentText("Unable to load settings file");
alert.showAndWait();
if (!promptResult.isPresent()) {
System.exit(1);
}
if (promptResult.get() == ButtonType.NO) {
System.exit(1);
}
settings = new MainSettings();
} else {
settings = result.getSuccess().get();
return;
}
settings = result.getSuccess().get();
selectedStationName.set(settings.getSelectedStationName());
if (selectedStationName.get() == null || selectedStationName.get() == "") {
@ -213,6 +209,8 @@ public class MainController implements Initializable {
.findFirst()
.orElse(null);
// TODO: if there are no stations, then create a default station and select that
if (selectedStation == null) {
logger.log(Level.SEVERE, "Selected station '" + selectedStationName.get() + "' not found");
selectedStation = settings.getStations().get(0);
@ -317,6 +315,8 @@ public class MainController implements Initializable {
settings.save();
// TODO: Load message from file
// If the message we're overwriting is different from its file, then prompt to confirm
Path nextMessagePath = selectedStation.stationPath().resolve("next-message.txt");
String messageText;

View File

@ -462,14 +462,8 @@ public class StationSettingsController {
} else if (osName.contains("nix") || osName.contains("nux") || osName.contains("aix")) {
LinuxScheduler.registerSchedule(settings);
} else {
String message = "Unsupported OS " + osName;
logger.log(Level.SEVERE, message);
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(message);
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
logger.log(Level.SEVERE, "Unsupported OS " + osName);
// TODO: Alert
}
Node node = (Node) e.getSource();

View File

@ -228,6 +228,7 @@ public class WindowsScheduler {
logger.info("Executable Path: " + executablePath);
Element command = doc.createElement("Command");
// TODO: need to figure out the real invocation
command.appendChild(doc.createTextNode(executablePath.toString()));
exec.appendChild(command);