Skip to content

Commit

Permalink
Merge pull request #19 from cryptomator/feature/tray-icon-loader
Browse files Browse the repository at this point in the history
polymorphic tray icon loading
  • Loading branch information
overheadhunter authored May 7, 2023
2 parents 90ad49c + 9daf5f6 commit 5b43e50
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.cryptomator.integrations.tray;

import org.jetbrains.annotations.ApiStatus;

/**
* A callback used by the {@link TrayMenuController} to load tray icons in the format required by the implementation.
*/
@ApiStatus.Experimental
sealed public interface TrayIconLoader permits TrayIconLoader.PngData, TrayIconLoader.FreedesktopIconName {

@FunctionalInterface
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);
}

@FunctionalInterface
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 5b43e50

Please sign in to comment.