Skip to content

Commit

Permalink
polymorphic tray icon loading
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed May 2, 2023
1 parent 90ad49c commit cdf313e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,20 +22,20 @@ static Optional<TrayMenuController> 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<TrayIconLoader> 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<TrayIconLoader> iconLoader);

/**
* Show the given options in the tray menu.
Expand Down

0 comments on commit cdf313e

Please sign in to comment.