diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 0f3f469..2ac9eaf 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,8 +1,10 @@ +import org.cryptomator.integrations.tray.TrayMenuController; import org.cryptomator.integrations.autostart.AutoStartProvider; import org.cryptomator.integrations.keychain.KeychainAccessProvider; import org.cryptomator.integrations.tray.TrayIntegrationProvider; import org.cryptomator.integrations.uiappearance.UiAppearanceProvider; + module org.cryptomator.integrations.api { exports org.cryptomator.integrations.autostart; exports org.cryptomator.integrations.keychain; @@ -12,5 +14,6 @@ uses AutoStartProvider; uses KeychainAccessProvider; uses TrayIntegrationProvider; + uses TrayMenuController; uses UiAppearanceProvider; } \ No newline at end of file diff --git a/src/main/java/org/cryptomator/integrations/tray/ActionItem.java b/src/main/java/org/cryptomator/integrations/tray/ActionItem.java new file mode 100644 index 0000000..383618b --- /dev/null +++ b/src/main/java/org/cryptomator/integrations/tray/ActionItem.java @@ -0,0 +1,4 @@ +package org.cryptomator.integrations.tray; + +public record ActionItem(String title, Runnable action) implements TrayMenuItem { +} diff --git a/src/main/java/org/cryptomator/integrations/tray/SeparatorItem.java b/src/main/java/org/cryptomator/integrations/tray/SeparatorItem.java new file mode 100644 index 0000000..7a4eab2 --- /dev/null +++ b/src/main/java/org/cryptomator/integrations/tray/SeparatorItem.java @@ -0,0 +1,4 @@ +package org.cryptomator.integrations.tray; + +public record SeparatorItem() implements TrayMenuItem { +} diff --git a/src/main/java/org/cryptomator/integrations/tray/SubMenuItem.java b/src/main/java/org/cryptomator/integrations/tray/SubMenuItem.java new file mode 100644 index 0000000..82a65bf --- /dev/null +++ b/src/main/java/org/cryptomator/integrations/tray/SubMenuItem.java @@ -0,0 +1,6 @@ +package org.cryptomator.integrations.tray; + +import java.util.List; + +public record SubMenuItem(String title, List items) implements TrayMenuItem { +} diff --git a/src/main/java/org/cryptomator/integrations/tray/TrayIntegrationProvider.java b/src/main/java/org/cryptomator/integrations/tray/TrayIntegrationProvider.java index 0c330e5..8650a2f 100644 --- a/src/main/java/org/cryptomator/integrations/tray/TrayIntegrationProvider.java +++ b/src/main/java/org/cryptomator/integrations/tray/TrayIntegrationProvider.java @@ -4,8 +4,17 @@ import java.util.Optional; +/** + * Allows to perform OS-specific tasks when the app gets minimized to or restored from a tray icon. + */ public interface TrayIntegrationProvider { + /** + * Loads the best-suited TrayIntegrationProvider. + * + * @return preferred TrayIntegrationProvider (if any) + * @since 1.1.0 + */ static Optional get() { return IntegrationsLoader.load(TrayIntegrationProvider.class); } diff --git a/src/main/java/org/cryptomator/integrations/tray/TrayMenuController.java b/src/main/java/org/cryptomator/integrations/tray/TrayMenuController.java new file mode 100644 index 0000000..48833af --- /dev/null +++ b/src/main/java/org/cryptomator/integrations/tray/TrayMenuController.java @@ -0,0 +1,40 @@ +package org.cryptomator.integrations.tray; + +import org.cryptomator.integrations.common.IntegrationsLoader; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Optional; + +/** + * Displays a tray icon and menu + * + * @since 1.1.0 + */ +public interface TrayMenuController { + + static Optional get() { + return IntegrationsLoader.load(TrayMenuController.class); + } + + /** + * Displays an icon on the system tray. + * + * @param rawImageData What image to show + * @param defaultAction Action to perform when interacting with the icon directly instead of its menu + * @param tooltip Text shown when hovering + * @throws IOException thrown when interacting with the given rawImageData + */ + void showTrayIcon(InputStream rawImageData, Runnable defaultAction, String tooltip) throws IOException; + + /** + * Show the given options in the tray menu. + *

+ * This method may be called multiple times, e.g. when the vault list changes. + * + * @param items Menu items + */ + void updateTrayMenu(List items); + +} diff --git a/src/main/java/org/cryptomator/integrations/tray/TrayMenuItem.java b/src/main/java/org/cryptomator/integrations/tray/TrayMenuItem.java new file mode 100644 index 0000000..a174c15 --- /dev/null +++ b/src/main/java/org/cryptomator/integrations/tray/TrayMenuItem.java @@ -0,0 +1,4 @@ +package org.cryptomator.integrations.tray; + +public sealed interface TrayMenuItem permits ActionItem, SubMenuItem, SeparatorItem { +}