Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue201/port-je-obsadeny-dialog #292

Merged
merged 6 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading