-
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.
- Loading branch information
Showing
14 changed files
with
219 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
# integrations-linux | ||
Linux-specific implemenations of the integrations-api | ||
Linux-specific implemenations of the [integrations-api](https://github.com/cryptomator/integrations-api). | ||
|
||
# Config | ||
|
||
This project uses the following JVM properties: | ||
* `cryptomator.integrationsLinux.trayIconsDir` - specifies the directory from which svg images for the tray icon are loaded | ||
|
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,24 @@ | ||
import org.cryptomator.integrations.keychain.KeychainAccessProvider; | ||
import org.cryptomator.integrations.revealpath.RevealPathService; | ||
import org.cryptomator.integrations.tray.TrayMenuController; | ||
import org.cryptomator.linux.keychain.KDEWalletKeychainAccess; | ||
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, KDEWalletKeychainAccess; | ||
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(); | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
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,127 @@ | ||
package org.cryptomator.linux.tray; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
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.NativeLibUtilities; | ||
|
||
import java.lang.foreign.Arena; | ||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.SegmentScope; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.Consumer; | ||
|
||
import static org.purejava.appindicator.app_indicator_h.*; | ||
|
||
@Priority(1000) | ||
@CheckAvailability | ||
@OperatingSystem(OperatingSystem.Value.LINUX) | ||
public class AppindicatorTrayMenuController implements TrayMenuController { | ||
private static final String APP_INDICATOR_ID = "org.cryptomator.Cryptomator"; | ||
private static final String SVG_SOURCE_PROPERTY = "cryptomator.integrationsLinux.trayIconsDir"; | ||
|
||
private static final SegmentScope SCOPE = SegmentScope.global(); | ||
private MemorySegment indicator; | ||
private MemorySegment menu = gtk_menu_new(); | ||
private Optional<String> svgSourcePath; | ||
|
||
@CheckAvailability | ||
public static boolean isAvailable() { | ||
return NativeLibUtilities.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()) { | ||
svgSourcePath = Optional.ofNullable(System.getProperty(SVG_SOURCE_PROPERTY)); | ||
// flatpak | ||
if (svgSourcePath.isEmpty()) { | ||
indicator = app_indicator_new(arena.allocateUtf8String(APP_INDICATOR_ID), | ||
arena.allocateUtf8String(s), | ||
APP_INDICATOR_CATEGORY_APPLICATION_STATUS()); | ||
// AppImage and ppa | ||
} else { | ||
indicator = app_indicator_new_with_path(arena.allocateUtf8String(APP_INDICATOR_ID), | ||
arena.allocateUtf8String(s), | ||
APP_INDICATOR_CATEGORY_APPLICATION_STATUS(), | ||
// find tray icons theme in mounted AppImage / installed on system by ppa | ||
arena.allocateUtf8String(svgSourcePath.get())); | ||
} | ||
} | ||
} | ||
|
||
@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 |
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 |
---|---|---|
@@ -1,19 +1,3 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.3.xsd"> | ||
<suppress> | ||
<notes><![CDATA[ | ||
Incorrectly matched CPE, see https://github.com/jeremylong/DependencyCheck/issues/4177git | ||
]]></notes> | ||
<gav regex="true">^org\.cryptomator:.*$</gav> | ||
<cpe>cpe:/a:cryptomator:cryptomator</cpe> | ||
<cve>CVE-2022-25366</cve> | ||
</suppress> | ||
<suppress> | ||
<notes><![CDATA[ | ||
False postive, because secret-service only accesses the external gnome-keyring service | ||
]]></notes> | ||
<gav regex="true">^de\.swiesend\:secret\-service:.*$</gav> | ||
<cve>CVE-2018-19358</cve> | ||
<cve>CVE-2018-20781</cve> | ||
</suppress> | ||
</suppressions> |