Skip to content

Commit cdf313e

Browse files
polymorphic tray icon loading
1 parent 90ad49c commit cdf313e

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.cryptomator.integrations.tray;
2+
3+
/**
4+
* A callback used by the {@link TrayMenuController} to load tray icons in the format required by the implementation.
5+
*/
6+
sealed public interface TrayIconLoader permits TrayIconLoader.PngData, TrayIconLoader.FreedesktopIconName {
7+
8+
non-sealed interface PngData extends TrayIconLoader {
9+
10+
/**
11+
* Loads an icon from a byte array holding a loaded PNG file.
12+
*
13+
* @param data png data
14+
*/
15+
void loadPng(byte[] data);
16+
}
17+
18+
non-sealed interface FreedesktopIconName extends TrayIconLoader {
19+
20+
/**
21+
* Loads an icon by looking it up {@code iconName} inside of {@code $XDG_DATA_DIRS/icons}.
22+
*
23+
* @param iconName the icon name
24+
*/
25+
void lookupByName(String iconName);
26+
}
27+
}

src/main/java/org/cryptomator/integrations/tray/TrayMenuController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import org.cryptomator.integrations.common.IntegrationsLoader;
44
import org.jetbrains.annotations.ApiStatus;
55

6-
import java.net.URI;
76
import java.util.List;
87
import java.util.Optional;
8+
import java.util.function.Consumer;
99

1010
/**
1111
* Displays a tray icon and menu
@@ -22,20 +22,20 @@ static Optional<TrayMenuController> get() {
2222
/**
2323
* Displays an icon on the system tray.
2424
*
25-
* @param imageUri What image to show
25+
* @param iconLoader A callback responsible for retrieving the icon in the required format
2626
* @param defaultAction Action to perform when interacting with the icon directly instead of its menu
2727
* @param tooltip Text shown when hovering
2828
* @throws TrayMenuException thrown when adding the tray icon failed
2929
*/
30-
void showTrayIcon(URI imageUri, Runnable defaultAction, String tooltip) throws TrayMenuException;
30+
void showTrayIcon(Consumer<TrayIconLoader> iconLoader, Runnable defaultAction, String tooltip) throws TrayMenuException;
3131

3232
/**
3333
* Updates the icon on the system tray.
3434
*
35-
* @param imageUri What image to show
35+
* @param iconLoader A callback responsible for retrieving the icon in the required format
3636
* @throws IllegalStateException thrown when called before an icon has been added
3737
*/
38-
void updateTrayIcon(URI imageUri);
38+
void updateTrayIcon(Consumer<TrayIconLoader> iconLoader);
3939

4040
/**
4141
* Show the given options in the tray menu.

0 commit comments

Comments
 (0)