-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from purejava/libappindicator
appindicator support
- Loading branch information
Showing
11 changed files
with
185 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import org.cryptomator.integrations.keychain.KeychainAccessProvider; | ||
import org.cryptomator.integrations.revealpath.RevealPathService; | ||
import org.cryptomator.integrations.tray.TrayMenuController; | ||
import org.cryptomator.linux.keychain.SecretServiceKeychainAccess; | ||
import org.cryptomator.linux.revealpath.DBusSendRevealPathService; | ||
import org.cryptomator.linux.tray.AppindicatorTrayMenuController; | ||
|
||
module org.cryptomator.integrations.linux { | ||
requires org.cryptomator.integrations.api; | ||
requires org.slf4j; | ||
requires com.google.common; | ||
requires org.apache.commons.lang3; | ||
requires org.freedesktop.dbus; | ||
requires org.purejava.appindicator; | ||
requires org.purejava.kwallet; | ||
requires secret.service; | ||
|
||
provides KeychainAccessProvider with SecretServiceKeychainAccess; | ||
provides RevealPathService with DBusSendRevealPathService; | ||
provides TrayMenuController with AppindicatorTrayMenuController; | ||
|
||
opens org.cryptomator.linux.tray to org.cryptomator.integrations.api; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/org/cryptomator/linux/tray/ActionItemCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.cryptomator.linux.tray; | ||
|
||
import org.cryptomator.integrations.tray.ActionItem; | ||
import org.purejava.appindicator.GCallback; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
record ActionItemCallback (ActionItem actionItem) implements GCallback { | ||
private static final Logger LOG = LoggerFactory.getLogger(ActionItemCallback.class); | ||
|
||
@Override | ||
public void apply() { | ||
LOG.trace("Hit tray menu action '{}'", actionItem.title()); | ||
actionItem.action().run(); | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
src/main/java/org/cryptomator/linux/tray/AppindicatorTrayMenuController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package org.cryptomator.linux.tray; | ||
|
||
import org.cryptomator.integrations.common.CheckAvailability; | ||
import org.cryptomator.integrations.common.OperatingSystem; | ||
import org.cryptomator.integrations.common.Priority; | ||
import org.cryptomator.integrations.tray.ActionItem; | ||
import org.cryptomator.integrations.tray.SeparatorItem; | ||
import org.cryptomator.integrations.tray.SubMenuItem; | ||
import org.cryptomator.integrations.tray.TrayIconLoader; | ||
import org.cryptomator.integrations.tray.TrayMenuController; | ||
import org.cryptomator.integrations.tray.TrayMenuException; | ||
import org.cryptomator.integrations.tray.TrayMenuItem; | ||
import org.purejava.appindicator.GCallback; | ||
import org.purejava.appindicator.MemoryAllocator; | ||
|
||
import java.lang.foreign.Arena; | ||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.SegmentScope; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
import static org.purejava.appindicator.app_indicator_h.*; | ||
|
||
@Priority(1000) | ||
@OperatingSystem(OperatingSystem.Value.LINUX) | ||
public class AppindicatorTrayMenuController implements TrayMenuController { | ||
|
||
private static final String APP_INDICATOR_ID = "org.cryptomator.Cryptomator"; | ||
|
||
private static final SegmentScope SCOPE = SegmentScope.global(); | ||
private MemorySegment indicator; | ||
private MemorySegment menu = gtk_menu_new(); | ||
|
||
@CheckAvailability | ||
public static boolean isAvailable() { | ||
return MemoryAllocator.isLoadedNativeLib(); | ||
} | ||
|
||
@Override | ||
public void showTrayIcon(Consumer<TrayIconLoader> iconLoader, Runnable runnable, String s) throws TrayMenuException { | ||
TrayIconLoader.FreedesktopIconName callback = this::showTrayIconWithSVG; | ||
iconLoader.accept(callback); | ||
gtk_widget_show_all(menu); | ||
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE()); | ||
} | ||
|
||
private void showTrayIconWithSVG(String s) { | ||
try (var arena = Arena.openConfined()) { | ||
indicator = app_indicator_new(arena.allocateUtf8String(APP_INDICATOR_ID), | ||
arena.allocateUtf8String(s), | ||
APP_INDICATOR_CATEGORY_APPLICATION_STATUS()); | ||
} | ||
} | ||
|
||
@Override | ||
public void updateTrayIcon(Consumer<TrayIconLoader> iconLoader) { | ||
TrayIconLoader.FreedesktopIconName callback = this::updateTrayIconWithSVG; | ||
iconLoader.accept(callback); | ||
} | ||
|
||
private void updateTrayIconWithSVG(String s) { | ||
try (var arena = Arena.openConfined()) { | ||
app_indicator_set_icon(indicator, arena.allocateUtf8String(s)); | ||
} | ||
} | ||
|
||
@Override | ||
public void updateTrayMenu(List<TrayMenuItem> items) throws TrayMenuException { | ||
menu = gtk_menu_new(); | ||
addChildren(menu, items); | ||
gtk_widget_show_all(menu); | ||
app_indicator_set_menu(indicator, menu); | ||
} | ||
|
||
@Override | ||
public void onBeforeOpenMenu(Runnable runnable) { | ||
|
||
} | ||
|
||
private void addChildren(MemorySegment menu, List<TrayMenuItem> items) { | ||
for (var item : items) { | ||
switch (item) { | ||
case ActionItem a -> { | ||
var gtkMenuItem = gtk_menu_item_new(); | ||
try (var arena = Arena.openConfined()) { | ||
gtk_menu_item_set_label(gtkMenuItem, arena.allocateUtf8String(a.title())); | ||
g_signal_connect_object(gtkMenuItem, | ||
arena.allocateUtf8String("activate"), | ||
GCallback.allocate(new ActionItemCallback(a), SCOPE), | ||
menu, | ||
0); | ||
} | ||
gtk_menu_shell_append(menu, gtkMenuItem); | ||
} | ||
case SeparatorItem separatorItem -> { | ||
var gtkSeparator = gtk_menu_item_new(); | ||
gtk_menu_shell_append(menu, gtkSeparator); | ||
} | ||
case SubMenuItem s -> { | ||
var gtkMenuItem = gtk_menu_item_new(); | ||
var gtkSubmenu = gtk_menu_new(); | ||
try (var arena = Arena.openConfined()) { | ||
gtk_menu_item_set_label(gtkMenuItem, arena.allocateUtf8String(s.title())); | ||
} | ||
addChildren(gtkSubmenu, s.items()); | ||
gtk_menu_item_set_submenu(gtkMenuItem, gtkSubmenu); | ||
gtk_menu_shell_append(menu, gtkMenuItem); | ||
} | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/main/resources/META-INF/services/org.cryptomator.integrations.tray.TrayMenuController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.cryptomator.linux.tray.AppindicatorTrayMenuController |