Skip to content
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
6 changes: 5 additions & 1 deletion src/main/java/github/weichware10/toolbox/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import github.weichware10.util.Logger;
import io.github.cdimascio.dotenv.Dotenv;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Rectangle2D;
import javafx.scene.image.Image;
import javafx.stage.Screen;
Expand All @@ -26,7 +27,8 @@ public static void main(String[] args) {
String logfile = String.format(
Dotenv.load().get("LOGS") + "/%s.log", DateTime.now().toString("yMMdd-HHmmss"));
Logger.setLogfile(logfile);
Util.deleteTempDir();
// delete temp dir
Runtime.getRuntime().addShutdownHook(Util.deleteTempDir());
launch(args);
}

Expand All @@ -49,6 +51,8 @@ public void start(Stage primaryStage) {
Rectangle2D screenBounds = Screen.getPrimary().getBounds();
primaryStage.setHeight(screenBounds.getHeight() / 2);
primaryStage.setWidth(screenBounds.getWidth() / 2);
// Hauptfenster schließt komplettes Programm
primaryStage.setOnCloseRequest(e -> Platform.exit());

// ersten Bildschirm starten
new App(primaryStage, null);
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/github/weichware10/toolbox/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ public static String saveImage(String imageUrl) throws MalformedURLException,
/**
* Löscht angelegten temporären Ordner beim Beenden der App.
*/
public static void deleteTempDir() {
Thread deleterHook = new Thread(() -> {
public static Thread deleteTempDir() {
return new Thread(() -> {
if (tmpdir == null) {
return;
}
try {
Logger.info("deleting tmp folder...");
FileUtils.deleteDirectory(new File(tmpdir));
Expand All @@ -94,6 +97,5 @@ public static void deleteTempDir() {
Logger.error("IllegalArgumentException while deleting tmpdir", e, true);
}
});
Runtime.getRuntime().addShutdownHook(deleterHook);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.Hyperlink;
Expand Down Expand Up @@ -105,14 +106,14 @@ public void setStatusIndicator(boolean active) {
} else {
statusBox.getChildren().remove(pi);
buttonBar.setDisable(false);
primaryStage.setOnCloseRequest(e -> closeProgram());
primaryStage.setOnCloseRequest(e -> Platform.exit());
}
}

@FXML
void closeProgram() {
Logger.info("end:content Closing Program");
end.closeProgramm();
Platform.exit();
}

@FXML
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/github/weichware10/toolbox/gui/PreTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package github.weichware10.toolbox.gui;

import github.weichware10.toolbox.codecharts.CodeCharts;
import github.weichware10.toolbox.gui.util.WindowCloser;
import github.weichware10.toolbox.zoommaps.ZoomMaps;
import github.weichware10.util.Logger;
import github.weichware10.util.config.ConfigClient;
Expand Down Expand Up @@ -61,7 +62,7 @@ public PreTest(Stage primaryStage,
Scene scene = new Scene(root);

// Event welches beim schließen eines Fensters aufgerufen wird
primaryStage.setOnCloseRequest(e -> Util.closeRequestFilter(e));
primaryStage.setOnCloseRequest(e -> WindowCloser.closeRequestFilter(e));
primaryStage.setScene(scene);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
package github.weichware10.toolbox.gui;
package github.weichware10.toolbox.gui.util;

import github.weichware10.toolbox.gui.dialogs.ConfirmDialog;
import javafx.application.Platform;
import javafx.stage.WindowEvent;

/**
* praktische Sachen für GUI.
* Event Filter für Schließen aller Fenster.
*/
public class Util {
public class WindowCloser {
/**
* Filtert Anfragen das Fenster zu schließen
* - wird das Event consumed, wird das Fenster nicht geschlossen.
*
* @param event - das WindowEvent mit der Anfrage
*/
public static void closeRequestFilter(WindowEvent event) {
String icon = Util.class.getResource("thonkang.png").toString();
String icon = WindowCloser.class.getResource("thonkang.png").toString();
// Fenster schließen, ja oder nein?
boolean confirmation = new ConfirmDialog("Do you want to close the window?", icon)
.getConfirmation();
// event consumieren -> nicht schließen
if (!confirmation) {
event.consume();
return;
}
// komplett schließen
Platform.exit();
}
}