Browse Source

remove AWT code and relocate to TrayMenuController

Edward Chow 2 years ago
parent
commit
f852ae0392

+ 1 - 1
pom.xml

@@ -29,7 +29,7 @@
 		<!-- cryptomator dependencies -->
 		<cryptomator.cryptolib.version>2.1.0-rc1</cryptomator.cryptolib.version>
 		<cryptomator.cryptofs.version>2.4.4</cryptomator.cryptofs.version>
-		<cryptomator.integrations.version>1.1.0</cryptomator.integrations.version>
+		<cryptomator.integrations.version>1.1.1</cryptomator.integrations.version>
 		<cryptomator.integrations.win.version>1.1.2</cryptomator.integrations.win.version>
 		<cryptomator.integrations.mac.version>1.1.2</cryptomator.integrations.mac.version>
 		<cryptomator.integrations.linux.version>1.1.0</cryptomator.integrations.linux.version>

+ 15 - 0
src/main/java/org/cryptomator/ui/traymenu/AwtTrayMenuController.java

@@ -19,6 +19,8 @@ import java.awt.PopupMenu;
 import java.awt.SystemTray;
 import java.awt.Toolkit;
 import java.awt.TrayIcon;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 import java.util.List;
 
 @CheckAvailability
@@ -58,6 +60,19 @@ public class AwtTrayMenuController implements TrayMenuController {
 		addChildren(menu, items);
 	}
 
+
+	@Override
+	public void onBeforeShow(Runnable listener) {
+		SystemTray systemTray = SystemTray.getSystemTray();
+		TrayIcon trayIcon = systemTray.getTrayIcons()[0];
+		trayIcon.addMouseListener(new MouseAdapter() {
+			@Override
+			public void mouseClicked(MouseEvent e) {
+				listener.run();
+			}
+		});
+	}
+
 	private void addChildren(Menu menu, List<TrayMenuItem> items) {
 		for (var item : items) {
 			// TODO: use Pattern Matching for switch, once available

+ 3 - 26
src/main/java/org/cryptomator/ui/traymenu/TrayMenuBuilder.java

@@ -70,32 +70,9 @@ public class TrayMenuBuilder {
 			trayMenu.showTrayIcon(image.readAllBytes(), this::showMainWindow, "Cryptomator");
 			SystemTray tray = SystemTray.getSystemTray();
 			TrayIcon trayIcon = tray.getTrayIcons()[0];
-			trayIcon.addMouseListener(new MouseListener() {
-				@Override
-				public void mouseClicked(MouseEvent e) {
-					for (Vault vault : vaults) {
-						VaultListManager.redetermineVaultState(vault);
-					}
-				}
-
-				@Override
-				public void mousePressed(MouseEvent e) {
-
-				}
-
-				@Override
-				public void mouseReleased(MouseEvent e) {
-
-				}
-
-				@Override
-				public void mouseEntered(MouseEvent e) {
-
-				}
-
-				@Override
-				public void mouseExited(MouseEvent e) {
-
+			trayMenu.onBeforeShow(() -> {
+				for (Vault vault : vaults) {
+					VaultListManager.redetermineVaultState(vault);
 				}
 			});
 			rebuildMenu();