diff --git a/src/main/java/org/cryptomator/integrations/tray/TrayIconLoader.java b/src/main/java/org/cryptomator/integrations/tray/TrayIconLoader.java new file mode 100644 index 0000000..bfa6365 --- /dev/null +++ b/src/main/java/org/cryptomator/integrations/tray/TrayIconLoader.java @@ -0,0 +1,27 @@ +package org.cryptomator.integrations.tray; + +/** + * A callback used by the {@link TrayMenuController} to load tray icons in the format required by the implementation. + */ +sealed public interface TrayIconLoader permits TrayIconLoader.PngData, TrayIconLoader.FreedesktopIconName { + + non-sealed interface PngData extends TrayIconLoader { + + /** + * Loads an icon from a byte array holding a loaded PNG file. + * + * @param data png data + */ + void loadPng(byte[] data); + } + + non-sealed interface FreedesktopIconName extends TrayIconLoader { + + /** + * Loads an icon by looking it up {@code iconName} inside of {@code $XDG_DATA_DIRS/icons}. + * + * @param iconName the icon name + */ + void lookupByName(String iconName); + } +} diff --git a/src/main/java/org/cryptomator/integrations/tray/TrayMenuController.java b/src/main/java/org/cryptomator/integrations/tray/TrayMenuController.java index 5cdd413..a1af384 100644 --- a/src/main/java/org/cryptomator/integrations/tray/TrayMenuController.java +++ b/src/main/java/org/cryptomator/integrations/tray/TrayMenuController.java @@ -3,9 +3,9 @@ import org.cryptomator.integrations.common.IntegrationsLoader; import org.jetbrains.annotations.ApiStatus; -import java.net.URI; import java.util.List; import java.util.Optional; +import java.util.function.Consumer; /** * Displays a tray icon and menu @@ -22,20 +22,20 @@ static Optional get() { /** * Displays an icon on the system tray. * - * @param imageUri What image to show + * @param iconLoader A callback responsible for retrieving the icon in the required format * @param defaultAction Action to perform when interacting with the icon directly instead of its menu * @param tooltip Text shown when hovering * @throws TrayMenuException thrown when adding the tray icon failed */ - void showTrayIcon(URI imageUri, Runnable defaultAction, String tooltip) throws TrayMenuException; + void showTrayIcon(Consumer iconLoader, Runnable defaultAction, String tooltip) throws TrayMenuException; /** * Updates the icon on the system tray. * - * @param imageUri What image to show + * @param iconLoader A callback responsible for retrieving the icon in the required format * @throws IllegalStateException thrown when called before an icon has been added */ - void updateTrayIcon(URI imageUri); + void updateTrayIcon(Consumer iconLoader); /** * Show the given options in the tray menu.