Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polymorphic tray icon loading #19

Merged
merged 2 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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