Make sure not to launch the FX app more than once.

This commit is contained in:
Sebastian Stenzel
2020-07-07 16:01:32 +02:00
parent cd1ed088c3
commit d3063c8117

View File

@@ -11,6 +11,7 @@ import javax.inject.Singleton;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
@Singleton
public class FxApplicationStarter {
@@ -19,17 +20,19 @@ public class FxApplicationStarter {
private final FxApplicationComponent.Builder fxAppComponent;
private final ExecutorService executor;
private final AtomicBoolean started;
private final CompletableFuture<FxApplication> future;
@Inject
public FxApplicationStarter(FxApplicationComponent.Builder fxAppComponent, ExecutorService executor) {
this.fxAppComponent = fxAppComponent;
this.executor = executor;
this.started = new AtomicBoolean();
this.future = new CompletableFuture<>();
}
public synchronized CompletionStage<FxApplication> get(boolean hasTrayIcon) {
if (!future.isDone()) {
public CompletionStage<FxApplication> get(boolean hasTrayIcon) {
if (!started.getAndSet(true)) {
start(hasTrayIcon);
}
return future;