Skip to content

Commit 5b43e50

Browse files
Merge pull request #19 from cryptomator/feature/tray-icon-loader
polymorphic tray icon loading
2 parents 90ad49c + 9daf5f6 commit 5b43e50

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

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

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)