mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 10:11:27 +00:00
Minimize mainwindow (instead of closing) when tray icon is not supported by the OS
This commit is contained in:
@@ -5,8 +5,11 @@
|
||||
*******************************************************************************/
|
||||
package org.cryptomator.ui.fxapp;
|
||||
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Subcomponent;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
@FxApplicationScoped
|
||||
@Subcomponent(modules = FxApplicationModule.class)
|
||||
public interface FxApplicationComponent {
|
||||
@@ -15,6 +18,9 @@ public interface FxApplicationComponent {
|
||||
|
||||
@Subcomponent.Builder
|
||||
interface Builder {
|
||||
|
||||
@BindsInstance
|
||||
Builder trayMenuSupported(@Named("trayMenuSupported") boolean trayMenuSupported);
|
||||
|
||||
FxApplicationComponent build();
|
||||
}
|
||||
|
||||
@@ -20,15 +20,17 @@ public class MainWindowController implements FxController {
|
||||
|
||||
private final Stage window;
|
||||
private final FxApplication application;
|
||||
private final boolean minimizeToSysTray;
|
||||
public HBox titleBar;
|
||||
public Region resizer;
|
||||
private double xOffset;
|
||||
private double yOffset;
|
||||
|
||||
@Inject
|
||||
public MainWindowController(@MainWindow Stage window, FxApplication application) {
|
||||
public MainWindowController(@MainWindow Stage window, FxApplication application, @Named("trayMenuSupported") boolean minimizeToSysTray) {
|
||||
this.window = window;
|
||||
this.application = application;
|
||||
this.minimizeToSysTray = minimizeToSysTray;
|
||||
}
|
||||
|
||||
@FXML
|
||||
@@ -51,7 +53,11 @@ public class MainWindowController implements FxController {
|
||||
|
||||
@FXML
|
||||
public void close() {
|
||||
window.close();
|
||||
if (minimizeToSysTray) {
|
||||
window.close();
|
||||
} else {
|
||||
window.setIconified(true);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
||||
@@ -24,9 +24,9 @@ public class FxApplicationStarter {
|
||||
this.future = new CompletableFuture<>();
|
||||
}
|
||||
|
||||
public synchronized FxApplication get() {
|
||||
public synchronized FxApplication get(boolean fromTrayMenu) {
|
||||
if (!future.isDone()) {
|
||||
start();
|
||||
start(fromTrayMenu);
|
||||
}
|
||||
try {
|
||||
return future.get();
|
||||
@@ -38,12 +38,12 @@ public class FxApplicationStarter {
|
||||
}
|
||||
}
|
||||
|
||||
private void start() {
|
||||
private void start(boolean fromTrayMenu) {
|
||||
LOG.debug("Starting JavaFX runtime...");
|
||||
Platform.startup(() -> {
|
||||
assert Platform.isFxApplicationThread();
|
||||
LOG.debug("JavaFX Runtime started.");
|
||||
FxApplication app = fxAppComponent.build().application();
|
||||
FxApplication app = fxAppComponent.trayMenuSupported(fromTrayMenu).build().application();
|
||||
app.start();
|
||||
future.complete(app);
|
||||
});
|
||||
|
||||
@@ -15,11 +15,14 @@ public interface TrayMenuComponent {
|
||||
|
||||
TrayIconController trayIconController();
|
||||
|
||||
FxApplicationStarter fxAppStarter();
|
||||
|
||||
default void addIconToSystemTray() {
|
||||
if (SystemTray.isSupported()) {
|
||||
trayIconController().initializeTrayIcon();
|
||||
} else {
|
||||
// TODO what?
|
||||
// show main window directly without any tray support:
|
||||
fxAppStarter().get(false).showMainWindow();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,11 +57,11 @@ class TrayMenuController {
|
||||
}
|
||||
|
||||
private void showMainWindow(ActionEvent actionEvent) {
|
||||
fxApplicationStarter.get().showMainWindow();
|
||||
fxApplicationStarter.get(true).showMainWindow();
|
||||
}
|
||||
|
||||
private void showPreferencesWindow(EventObject actionEvent) {
|
||||
fxApplicationStarter.get().showPreferencesWindow();
|
||||
fxApplicationStarter.get(true).showPreferencesWindow();
|
||||
}
|
||||
|
||||
private void quitApplication(ActionEvent actionEvent) {
|
||||
|
||||
Reference in New Issue
Block a user