|
@@ -7,6 +7,7 @@ import org.cryptomator.common.vaults.VaultListManager;
|
|
|
import org.cryptomator.integrations.tray.ActionItem;
|
|
|
import org.cryptomator.integrations.tray.SeparatorItem;
|
|
|
import org.cryptomator.integrations.tray.SubMenuItem;
|
|
|
+import org.cryptomator.integrations.tray.TrayIconLoader;
|
|
|
import org.cryptomator.integrations.tray.TrayMenuController;
|
|
|
import org.cryptomator.integrations.tray.TrayMenuException;
|
|
|
import org.cryptomator.integrations.tray.TrayMenuItem;
|
|
@@ -23,9 +24,7 @@ import javafx.beans.Observable;
|
|
|
import javafx.collections.ObservableList;
|
|
|
import java.io.IOException;
|
|
|
import java.io.UncheckedIOException;
|
|
|
-import java.net.URI;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Base64;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
import java.util.ResourceBundle;
|
|
@@ -38,10 +37,6 @@ public class TrayMenuBuilder {
|
|
|
private static final String TRAY_ICON_UNLOCKED_MAC = "/img/tray_icon_unlocked_mac@2x.png";
|
|
|
private static final String TRAY_ICON = "/img/tray_icon.png";
|
|
|
private static final String TRAY_ICON_UNLOCKED = "/img/tray_icon_unlocked.png";
|
|
|
- private static final String TRAY_ICON_SVG = "tray_icon.svg";
|
|
|
- private static final String TRAY_ICON_UNLOCKED_SVG = "tray_icon_unlocked.svg";
|
|
|
- private static final String DATA_URI_SCHEME = "data:image/png;base64,";
|
|
|
- private static final String FILE_URI_SCHEME = "file:///";
|
|
|
|
|
|
private final ResourceBundle resourceBundle;
|
|
|
private final VaultService vaultService;
|
|
@@ -71,7 +66,12 @@ public class TrayMenuBuilder {
|
|
|
});
|
|
|
|
|
|
try {
|
|
|
- trayMenu.showTrayIcon(getAppropriateTrayIconImage(), this::showMainWindow, "Cryptomator");
|
|
|
+ trayMenu.showTrayIcon(loader -> {
|
|
|
+ switch (loader) {
|
|
|
+ case TrayIconLoader.PngData l -> l.loadPng(getAppropriateTrayIconImage());
|
|
|
+ case TrayIconLoader.FreedesktopIconName l -> l.lookupByName(getAppropriateTrayIconSVG());
|
|
|
+ }
|
|
|
+ }, this::showMainWindow, "Cryptomator");
|
|
|
trayMenu.onBeforeOpenMenu(() -> {
|
|
|
for (Vault vault : vaults) {
|
|
|
VaultListManager.redetermineVaultState(vault);
|
|
@@ -90,7 +90,12 @@ public class TrayMenuBuilder {
|
|
|
|
|
|
private void vaultListChanged(@SuppressWarnings("unused") Observable observable) {
|
|
|
assert Platform.isFxApplicationThread();
|
|
|
- trayMenu.updateTrayIcon(getAppropriateTrayIconImage());
|
|
|
+ trayMenu.updateTrayIcon(loader -> {
|
|
|
+ switch (loader) {
|
|
|
+ case TrayIconLoader.PngData l -> l.loadPng(getAppropriateTrayIconImage());
|
|
|
+ case TrayIconLoader.FreedesktopIconName l -> l.lookupByName(getAppropriateTrayIconSVG());
|
|
|
+ }
|
|
|
+ });
|
|
|
rebuildMenu();
|
|
|
}
|
|
|
|
|
@@ -161,16 +166,10 @@ public class TrayMenuBuilder {
|
|
|
appWindows.showPreferencesWindow(SelectedPreferencesTab.ANY);
|
|
|
}
|
|
|
|
|
|
- private URI getAppropriateTrayIconImage() {
|
|
|
+ private byte[] getAppropriateTrayIconImage() {
|
|
|
boolean isAnyVaultUnlocked = vaults.stream().anyMatch(Vault::isUnlocked);
|
|
|
|
|
|
String resourceName;
|
|
|
-
|
|
|
- if (SystemUtils.IS_OS_LINUX) {
|
|
|
- resourceName = isAnyVaultUnlocked ? TRAY_ICON_UNLOCKED_SVG : TRAY_ICON_SVG;
|
|
|
- return URI.create(FILE_URI_SCHEME + resourceName);
|
|
|
- }
|
|
|
-
|
|
|
if (SystemUtils.IS_OS_MAC_OSX) {
|
|
|
resourceName = isAnyVaultUnlocked ? TRAY_ICON_UNLOCKED_MAC : TRAY_ICON_MAC;
|
|
|
} else {
|
|
@@ -179,11 +178,15 @@ public class TrayMenuBuilder {
|
|
|
|
|
|
try (var image = getClass().getResourceAsStream(resourceName)) {
|
|
|
assert image != null;
|
|
|
- var imageBytes = image.readAllBytes();
|
|
|
- var data = Base64.getEncoder().encodeToString(imageBytes);
|
|
|
- return URI.create(DATA_URI_SCHEME + data);
|
|
|
+ return image.readAllBytes();
|
|
|
} catch (IOException e) {
|
|
|
throw new UncheckedIOException("Failed to load tray icon image: " + resourceName, e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private String getAppropriateTrayIconSVG() {
|
|
|
+ boolean isAnyVaultUnlocked = vaults.stream().anyMatch(Vault::isUnlocked);
|
|
|
+
|
|
|
+ return isAnyVaultUnlocked ? "org.cryptomator.Cryptomator-unlocked" : "org.cryptomator.Cryptomator";
|
|
|
+ }
|
|
|
}
|