Skip to content

Commit af59966

Browse files
Merge pull request #6 from cryptomator/feature/tray-menu
Add Tray Menu API
2 parents d575f5d + e4137ff commit af59966

File tree

7 files changed

+70
-0
lines changed

7 files changed

+70
-0
lines changed

src/main/java/module-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import org.cryptomator.integrations.tray.TrayMenuController;
12
import org.cryptomator.integrations.autostart.AutoStartProvider;
23
import org.cryptomator.integrations.keychain.KeychainAccessProvider;
34
import org.cryptomator.integrations.tray.TrayIntegrationProvider;
45
import org.cryptomator.integrations.uiappearance.UiAppearanceProvider;
56

7+
68
module org.cryptomator.integrations.api {
79
exports org.cryptomator.integrations.autostart;
810
exports org.cryptomator.integrations.keychain;
@@ -12,5 +14,6 @@
1214
uses AutoStartProvider;
1315
uses KeychainAccessProvider;
1416
uses TrayIntegrationProvider;
17+
uses TrayMenuController;
1518
uses UiAppearanceProvider;
1619
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.cryptomator.integrations.tray;
2+
3+
public record ActionItem(String title, Runnable action) implements TrayMenuItem {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.cryptomator.integrations.tray;
2+
3+
public record SeparatorItem() implements TrayMenuItem {
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.cryptomator.integrations.tray;
2+
3+
import java.util.List;
4+
5+
public record SubMenuItem(String title, List<TrayMenuItem> items) implements TrayMenuItem {
6+
}

src/main/java/org/cryptomator/integrations/tray/TrayIntegrationProvider.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44

55
import java.util.Optional;
66

7+
/**
8+
* Allows to perform OS-specific tasks when the app gets minimized to or restored from a tray icon.
9+
*/
710
public interface TrayIntegrationProvider {
811

12+
/**
13+
* Loads the best-suited TrayIntegrationProvider.
14+
*
15+
* @return preferred TrayIntegrationProvider (if any)
16+
* @since 1.1.0
17+
*/
918
static Optional<TrayIntegrationProvider> get() {
1019
return IntegrationsLoader.load(TrayIntegrationProvider.class);
1120
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.cryptomator.integrations.tray;
2+
3+
import org.cryptomator.integrations.common.IntegrationsLoader;
4+
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.util.List;
8+
import java.util.Optional;
9+
10+
/**
11+
* Displays a tray icon and menu
12+
*
13+
* @since 1.1.0
14+
*/
15+
public interface TrayMenuController {
16+
17+
static Optional<TrayMenuController> get() {
18+
return IntegrationsLoader.load(TrayMenuController.class);
19+
}
20+
21+
/**
22+
* Displays an icon on the system tray.
23+
*
24+
* @param rawImageData What image to show
25+
* @param defaultAction Action to perform when interacting with the icon directly instead of its menu
26+
* @param tooltip Text shown when hovering
27+
* @throws IOException thrown when interacting with the given <code>rawImageData</code>
28+
*/
29+
void showTrayIcon(InputStream rawImageData, Runnable defaultAction, String tooltip) throws IOException;
30+
31+
/**
32+
* Show the given options in the tray menu.
33+
* <p>
34+
* This method may be called multiple times, e.g. when the vault list changes.
35+
*
36+
* @param items Menu items
37+
*/
38+
void updateTrayMenu(List<TrayMenuItem> items);
39+
40+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.cryptomator.integrations.tray;
2+
3+
public sealed interface TrayMenuItem permits ActionItem, SubMenuItem, SeparatorItem {
4+
}

0 commit comments

Comments
 (0)