Skip to content

Commit

Permalink
Merge pull request #292 from slovensko-digital/issue201/port-je-obsad…
Browse files Browse the repository at this point in the history
…eny-dialog

issue201/port-je-obsadeny-dialog
  • Loading branch information
celuchmarek authored Nov 15, 2024
2 parents 412b886 + ca6e649 commit 748d17c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package digital.slovensko.autogram.core.errors;

public class PortIsUsedException extends AutogramException {
public PortIsUsedException() {
super("Nepodarilo sa spustiť server", "Autogram je spustený bez možnosti podpisovania z prehliadača", "Port, ktorý používa Autogram server, je momentálne obsadený inou aplikáciou. Autogram sa preto spustil bez možnosti podpisovania z prehliadača. Overovanie a podpisovanie súborov v desktopovom režime je funkčné.\n\nAk chcete Autogram používať plnohodnotne, zatvorte danú aplikáciu a skúste spustiť Autogram znova.", null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.sun.net.httpserver.HttpsServer;

import digital.slovensko.autogram.core.Autogram;
import digital.slovensko.autogram.core.errors.PortIsUsedException;
import digital.slovensko.autogram.server.filters.AutogramCorsFilter;

public class AutogramServer {
Expand Down Expand Up @@ -93,7 +94,7 @@ public void configure(HttpsParameters params) {
return server;

} catch (BindException e) {
throw new RuntimeException("error.launchFailed.header port is already in use", e); // TODO
throw new PortIsUsedException();

} catch (Exception e) {
throw new RuntimeException("error.serverNotCreated", e); // TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public class ErrorController implements SuppressedFocusController {
private final AutogramException exception;
private final boolean errorDetailsDisabled;

@FXML
VBox mainBox;
Expand All @@ -21,10 +22,20 @@ public class ErrorController implements SuppressedFocusController {

public ErrorController(AutogramException e) {
this.exception = e;
this.errorDetailsDisabled = false;
}

public ErrorController(AutogramException e, boolean errorDetailsDisabled) {
this.exception = e;
this.errorDetailsDisabled = errorDetailsDisabled;
}


public void initialize() {
errorSummaryComponentController.setException(exception);

if (errorDetailsDisabled)
errorSummaryComponentController.disableErrorDetails();
}

public void onMainButtonAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public void setException(AutogramException e) {
}
}

public void disableErrorDetails() {
showErrorDetailsButton.setVisible(false);
showErrorDetailsButton.setManaged(false);
}

public void initialize() {
}

Expand Down
40 changes: 27 additions & 13 deletions src/main/java/digital/slovensko/autogram/ui/gui/GUIApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import digital.slovensko.autogram.core.Autogram;
import digital.slovensko.autogram.core.LaunchParameters;
import digital.slovensko.autogram.core.UserSettings;
import digital.slovensko.autogram.core.errors.PortIsUsedException;
import digital.slovensko.autogram.core.errors.UnrecognizedException;
import digital.slovensko.autogram.server.AutogramServer;
import javafx.application.Application;
Expand All @@ -26,6 +27,7 @@ public void start(Stage windowStage) throws Exception {

Platform.setImplicitExit(false);
setUserAgentStylesheet(getClass().getResource("idsk.css").toExternalForm());
var titleString = "Autogram";

final Autogram autogram;
autogram = new Autogram(new GUI(getHostServices(), userSettings), userSettings);
Expand All @@ -35,29 +37,41 @@ public void start(Stage windowStage) throws Exception {
final var params = LaunchParameters.fromParameters(getParameters());
final var controller = new MainMenuController(autogram, userSettings);

server = new AutogramServer(autogram, params.getHost(), params.getPort(), params.isProtocolHttps(), cachedExecutorService);
if (!params.isStandaloneMode())
GUIUtils.startIconified(windowStage);

if (userSettings.isServerEnabled()) {
server.start();
}
try {
server = new AutogramServer(autogram, params.getHost(), params.getPort(), params.isProtocolHttps(), cachedExecutorService);
server.start();

var thread = new Thread(server::stop);
windowStage.setOnCloseRequest(event -> {
thread.start();
Platform.exit();
});

Thread thread = new Thread(server::stop);
windowStage.setOnCloseRequest(event -> {
if (userSettings.isServerEnabled()) {
thread.start();
}
Platform.exit();
});
} catch (PortIsUsedException e) {
Platform.runLater(() -> {
GUIUtils.showError(e, "Pokračovať v obmedzenom režime", true, true);
});

server = null;
titleString = "Autogram (obmedzený režim)";
}
}

if (!params.isStandaloneMode())
GUIUtils.startIconified(windowStage);
if (server == null)
windowStage.setOnCloseRequest(event -> {
Platform.exit();
});

GUIUtils.suppressDefaultFocus(windowStage, controller);
windowStage.setTitle("Autogram");
windowStage.setTitle(titleString);
windowStage.setScene(new Scene(GUIUtils.loadFXML(controller, "main-menu.fxml")));
windowStage.setResizable(false);
windowStage.show();

} catch (Exception e) {
//ak nastane chyba, zobrazíme chybové okno a ukončíme aplikáciu
final var serverFinal = server; //pomocná premenná, do lambda výrazu nižšie musí vstupovať finalna premenná
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ public static void hackToForceRelayout(Stage stage) {
}

public static void showError(AutogramException e, String buttonText, boolean wait) {
showError(e, buttonText, wait, false);
}

public static void showError(AutogramException e, String buttonText, boolean wait, boolean errorDetailsDisabled) {
logger.debug("GUI showing error", e);
var controller = new ErrorController(e);
var controller = new ErrorController(e, errorDetailsDisabled);
var root = GUIUtils.loadFXML(controller, "error-dialog.fxml");
controller.setMainButtonText(buttonText);

Expand Down

0 comments on commit 748d17c

Please sign in to comment.