18
18
import java .lang .foreign .MemorySegment ;
19
19
import java .lang .foreign .SegmentScope ;
20
20
import java .util .List ;
21
+ import java .util .Optional ;
21
22
import java .util .function .Consumer ;
22
23
23
24
import static org .purejava .appindicator .app_indicator_h .*;
27
28
@ OperatingSystem (OperatingSystem .Value .LINUX )
28
29
public class AppindicatorTrayMenuController implements TrayMenuController {
29
30
private static final String APP_INDICATOR_ID = "org.cryptomator.Cryptomator" ;
31
+ private static final String SVG_SOURCE_PROPERTY = "cryptomator.integrationsLinux.trayIconsDir" ;
30
32
31
33
private static final SegmentScope SCOPE = SegmentScope .global ();
32
34
private MemorySegment indicator ;
33
35
private MemorySegment menu = gtk_menu_new ();
36
+ private Optional <String > svgSourcePath ;
34
37
35
38
@ CheckAvailability
36
39
public static boolean isAvailable () {
@@ -47,18 +50,20 @@ public void showTrayIcon(Consumer<TrayIconLoader> iconLoader, Runnable runnable,
47
50
48
51
private void showTrayIconWithSVG (String s ) {
49
52
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 ()));
53
66
}
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" ));
62
67
}
63
68
}
64
69
0 commit comments