Преглед изворни кода

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

Sebastian Stenzel пре 4 година
родитељ
комит
d3063c8117

+ 5 - 2
main/ui/src/main/java/org/cryptomator/ui/launcher/FxApplicationStarter.java

@@ -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;