cancel background task, if window is closed

This commit is contained in:
Armin Schrenk 2023-11-30 11:18:33 +01:00
parent b895ac69fb
commit 43ad1c05c0
No known key found for this signature in database
GPG Key ID: 8F2992163CBBA7FC

View File

@ -131,7 +131,16 @@ public class CreateNewVaultLocationController implements FxController {
@FXML @FXML
public void initialize() { public void initialize() {
backgroundExecutor.submit(this::loadLocationPresets); var task = backgroundExecutor.submit(this::loadLocationPresets);
var onHiddenAction = window.getOnHidden();
if(onHiddenAction != null) {
window.setOnHidden(evt -> {
task.cancel(true);
onHiddenAction.handle(evt);
});
} else {
window.setOnHidden(_ -> task.cancel(true));
}
locationPresetsToggler.selectedToggleProperty().addListener(this::togglePredefinedLocation); locationPresetsToggler.selectedToggleProperty().addListener(this::togglePredefinedLocation);
usePresetPath.bind(locationPresetsToggler.selectedToggleProperty().isNotEqualTo(customRadioButton)); usePresetPath.bind(locationPresetsToggler.selectedToggleProperty().isNotEqualTo(customRadioButton));
} }