Browse Source

No longer using TrayIcon on linux systems

* Reason: TrayIcon not supported well on linux and caused problems
* Renamed TrayIconUtil to ExitUtil
* fixes #177
Markus Kreusch 9 years ago
parent
commit
d0dc8819f4

+ 1 - 1
main/ui/src/main/java/org/cryptomator/ui/CryptomatorComponent.java

@@ -29,5 +29,5 @@ interface CryptomatorComponent {
 
 	Localization localization();
 
-	TrayIconUtil trayIconUtil();
+	ExitUtil exitUtil();
 }

+ 23 - 4
main/ui/src/main/java/org/cryptomator/ui/TrayIconUtil.java

@@ -38,22 +38,41 @@ import javafx.application.Platform;
 import javafx.stage.Stage;
 
 @Singleton
-class TrayIconUtil {
+class ExitUtil {
 
-	private static final Logger LOG = LoggerFactory.getLogger(TrayIconUtil.class);
+	private static final Logger LOG = LoggerFactory.getLogger(ExitUtil.class);
 
 	private final Stage mainWindow;
 	private final Localization localization;
 	private final Settings settings;
 
 	@Inject
-	public TrayIconUtil(@Named("mainWindow") Stage mainWindow, Localization localization, Settings settings) {
+	public ExitUtil(@Named("mainWindow") Stage mainWindow, Localization localization, Settings settings) {
 		this.mainWindow = mainWindow;
 		this.localization = localization;
 		this.settings = settings;
 	}
 
-	public void initTrayIcon(Runnable exitCommand) {
+	public void initExitHandler(Runnable exitCommand) {
+		if (SystemUtils.IS_OS_LINUX) {
+			initMinimizeExitHandler(exitCommand);
+		} else {
+			initTrayIconExitHandler(exitCommand);
+		}
+	}
+
+	private void initMinimizeExitHandler(Runnable exitCommand) {
+		mainWindow.setOnCloseRequest(e -> {
+			if (Platform.isImplicitExit()) {
+				exitCommand.run();
+			} else {
+				mainWindow.setIconified(true);
+				e.consume();
+			}
+		});
+	}
+
+	private void initTrayIconExitHandler(Runnable exitCommand) {
 		final TrayIcon trayIcon = createTrayIcon(exitCommand);
 		try {
 			SystemTray.getSystemTray().add(trayIcon);

+ 1 - 1
main/ui/src/main/java/org/cryptomator/ui/MainApplication.java

@@ -67,7 +67,7 @@ public class MainApplication extends Application {
 		// show window and start observing its focus:
 		primaryStage.show();
 		ActiveWindowStyleSupport.startObservingFocus(primaryStage);
-		comp.trayIconUtil().initTrayIcon(this::quit);
+		comp.exitUtil().initExitHandler(this::quit);
 
 		// open files, if requested during startup:
 		for (String arg : getParameters().getUnnamed()) {