mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-20 11:41:26 +00:00
Show TrayMenu sooner, don't wait for FxApplication to initialize
This commit is contained in:
@@ -8,44 +8,44 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
@TrayMenuScoped
|
||||
public class FxApplicationStarter {
|
||||
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FxApplicationStarter.class);
|
||||
|
||||
private final CompletableFuture<FxApplication> future;
|
||||
private final FxApplicationComponent.Builder fxAppComponent;
|
||||
private final ExecutorService executor;
|
||||
private final CompletableFuture<FxApplication> future;
|
||||
|
||||
@Inject
|
||||
public FxApplicationStarter(FxApplicationComponent.Builder fxAppComponent) {
|
||||
public FxApplicationStarter(FxApplicationComponent.Builder fxAppComponent, ExecutorService executor) {
|
||||
this.fxAppComponent = fxAppComponent;
|
||||
this.executor = executor;
|
||||
this.future = new CompletableFuture<>();
|
||||
}
|
||||
|
||||
public synchronized FxApplication get(boolean fromTrayMenu) {
|
||||
public synchronized CompletionStage<FxApplication> get(boolean fromTrayMenu) {
|
||||
if (!future.isDone()) {
|
||||
start(fromTrayMenu);
|
||||
}
|
||||
try {
|
||||
return future.get();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("Interrupted while waiting for FxApplication startup.", e);
|
||||
} catch (ExecutionException e) {
|
||||
throw new IllegalStateException("FxApplication startup failed.", e);
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
||||
private void start(boolean fromTrayMenu) {
|
||||
LOG.debug("Starting JavaFX runtime...");
|
||||
Platform.startup(() -> {
|
||||
assert Platform.isFxApplicationThread();
|
||||
LOG.debug("JavaFX Runtime started.");
|
||||
FxApplication app = fxAppComponent.trayMenuSupported(fromTrayMenu).build().application();
|
||||
app.start();
|
||||
future.complete(app);
|
||||
executor.submit(() -> {
|
||||
LOG.info("Starting JavaFX runtime...");
|
||||
Platform.startup(() -> {
|
||||
assert Platform.isFxApplicationThread();
|
||||
LOG.info("JavaFX Runtime started.");
|
||||
FxApplication app = fxAppComponent.trayMenuSupported(fromTrayMenu).build().application();
|
||||
app.start();
|
||||
future.complete(app);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,6 @@ public class TrayIconController {
|
||||
|
||||
public void initializeTrayIcon() {
|
||||
settings.theme().addListener(this::themeChanged);
|
||||
|
||||
trayMenuController.initTrayMenu();
|
||||
|
||||
try {
|
||||
SystemTray.getSystemTray().add(trayIcon);
|
||||
@@ -39,6 +37,8 @@ public class TrayIconController {
|
||||
} catch (AWTException e) {
|
||||
LOG.error("Error adding tray icon", e);
|
||||
}
|
||||
|
||||
trayMenuController.initTrayMenu();
|
||||
}
|
||||
|
||||
private void themeChanged(@SuppressWarnings("unused") Observable observable) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.cryptomator.ui.traymenu;
|
||||
|
||||
import dagger.Subcomponent;
|
||||
import org.cryptomator.ui.fxapp.FxApplication;
|
||||
|
||||
import java.awt.SystemTray;
|
||||
|
||||
@@ -22,7 +23,7 @@ public interface TrayMenuComponent {
|
||||
trayIconController().initializeTrayIcon();
|
||||
} else {
|
||||
// show main window directly without any tray support:
|
||||
fxAppStarter().get(false).showMainWindow();
|
||||
fxAppStarter().get(false).thenAccept(FxApplication::showMainWindow);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ import javafx.beans.Observable;
|
||||
import javafx.collections.ObservableList;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.ui.fxapp.FxApplication;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
@@ -16,6 +19,8 @@ import java.util.concurrent.CountDownLatch;
|
||||
|
||||
@TrayMenuScoped
|
||||
class TrayMenuController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TrayMenuController.class);
|
||||
|
||||
private final FxApplicationStarter fxApplicationStarter;
|
||||
private final CountDownLatch shutdownLatch;
|
||||
@@ -48,7 +53,6 @@ class TrayMenuController {
|
||||
|
||||
// show window on start?
|
||||
if (!settings.startHidden().get()) {
|
||||
// TODO: schedule async to not delay tray menu initialization
|
||||
showMainWindow(null);
|
||||
}
|
||||
}
|
||||
@@ -83,11 +87,11 @@ class TrayMenuController {
|
||||
}
|
||||
|
||||
private void showMainWindow(ActionEvent actionEvent) {
|
||||
fxApplicationStarter.get(true).showMainWindow();
|
||||
fxApplicationStarter.get(true).thenAccept(FxApplication::showMainWindow);
|
||||
}
|
||||
|
||||
private void showPreferencesWindow(EventObject actionEvent) {
|
||||
fxApplicationStarter.get(true).showPreferencesWindow();
|
||||
fxApplicationStarter.get(true).thenAccept(FxApplication::showPreferencesWindow);
|
||||
}
|
||||
|
||||
private void quitApplication(ActionEvent actionEvent) {
|
||||
|
||||
Reference in New Issue
Block a user