1818import java .lang .foreign .MemorySegment ;
1919import java .lang .foreign .SegmentScope ;
2020import java .util .List ;
21+ import java .util .Optional ;
2122import java .util .function .Consumer ;
2223
2324import static org .purejava .appindicator .app_indicator_h .*;
2728@ OperatingSystem (OperatingSystem .Value .LINUX )
2829public class AppindicatorTrayMenuController implements TrayMenuController {
2930 private static final String APP_INDICATOR_ID = "org.cryptomator.Cryptomator" ;
31+ private static final String SVG_SOURCE_PROPERTY = "cryptomator.integrationsLinux.trayIconsDir" ;
3032
3133 private static final SegmentScope SCOPE = SegmentScope .global ();
3234 private MemorySegment indicator ;
3335 private MemorySegment menu = gtk_menu_new ();
36+ private Optional <String > svgSourcePath ;
3437
3538 @ CheckAvailability
3639 public static boolean isAvailable () {
@@ -47,18 +50,20 @@ public void showTrayIcon(Consumer<TrayIconLoader> iconLoader, Runnable runnable,
4750
4851 private void showTrayIconWithSVG (String s ) {
4952 try (var arena = Arena .openConfined ()) {
50- var appdir = System .getenv ("APPDIR" );
51- if (null == appdir || appdir .isBlank ()) {
52- appdir = "" ;
53+ svgSourcePath = Optional .ofNullable (System .getProperty (SVG_SOURCE_PROPERTY ));
54+ // flatpak
55+ if (svgSourcePath .isEmpty ()) {
56+ indicator = app_indicator_new (arena .allocateUtf8String (APP_INDICATOR_ID ),
57+ arena .allocateUtf8String (s ),
58+ APP_INDICATOR_CATEGORY_APPLICATION_STATUS ());
59+ // AppImage and ppa
60+ } else {
61+ indicator = app_indicator_new_with_path (arena .allocateUtf8String (APP_INDICATOR_ID ),
62+ arena .allocateUtf8String (s ),
63+ APP_INDICATOR_CATEGORY_APPLICATION_STATUS (),
64+ // find tray icons theme in mounted AppImage / installed on system by ppa
65+ arena .allocateUtf8String (svgSourcePath .get ()));
5366 }
54- if (appdir .endsWith ("/" )) {
55- appdir = StringUtils .chop (appdir );
56- }
57- indicator = app_indicator_new_with_path (arena .allocateUtf8String (APP_INDICATOR_ID ),
58- arena .allocateUtf8String (s ),
59- APP_INDICATOR_CATEGORY_APPLICATION_STATUS (),
60- // find tray icons theme in mounted AppImage
61- arena .allocateUtf8String (appdir + "/usr/share/icons/hicolor/symbolic/apps" ));
6267 }
6368 }
6469
0 commit comments