1
1
package org .cryptomator .linux .tray ;
2
2
3
+ import org .apache .commons .lang3 .StringUtils ;
3
4
import org .cryptomator .integrations .common .CheckAvailability ;
4
5
import org .cryptomator .integrations .common .OperatingSystem ;
5
6
import org .cryptomator .integrations .common .Priority ;
11
12
import org .cryptomator .integrations .tray .TrayMenuException ;
12
13
import org .cryptomator .integrations .tray .TrayMenuItem ;
13
14
import org .purejava .appindicator .GCallback ;
14
- import org .purejava .appindicator .MemoryAllocator ;
15
+ import org .purejava .appindicator .NativeLibUtilities ;
15
16
16
17
import java .lang .foreign .Arena ;
17
18
import java .lang .foreign .MemorySegment ;
18
19
import java .lang .foreign .SegmentScope ;
19
20
import java .util .List ;
21
+ import java .util .Optional ;
20
22
import java .util .function .Consumer ;
21
23
22
24
import static org .purejava .appindicator .app_indicator_h .*;
23
25
24
26
@ Priority (1000 )
27
+ @ CheckAvailability
25
28
@ OperatingSystem (OperatingSystem .Value .LINUX )
26
29
public class AppindicatorTrayMenuController implements TrayMenuController {
27
-
28
30
private static final String APP_INDICATOR_ID = "org.cryptomator.Cryptomator" ;
31
+ private static final String SVG_SOURCE_PROPERTY = "cryptomator.integrationsLinux.trayIconsDir" ;
29
32
30
33
private static final SegmentScope SCOPE = SegmentScope .global ();
31
34
private MemorySegment indicator ;
32
35
private MemorySegment menu = gtk_menu_new ();
36
+ private Optional <String > svgSourcePath ;
33
37
34
38
@ CheckAvailability
35
39
public static boolean isAvailable () {
36
- return MemoryAllocator .isLoadedNativeLib ();
40
+ return NativeLibUtilities .isLoadedNativeLib ();
37
41
}
38
42
39
43
@ Override
@@ -46,9 +50,20 @@ public void showTrayIcon(Consumer<TrayIconLoader> iconLoader, Runnable runnable,
46
50
47
51
private void showTrayIconWithSVG (String s ) {
48
52
try (var arena = Arena .openConfined ()) {
49
- indicator = app_indicator_new (arena .allocateUtf8String (APP_INDICATOR_ID ),
50
- arena .allocateUtf8String (s ),
51
- APP_INDICATOR_CATEGORY_APPLICATION_STATUS ());
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 ()));
66
+ }
52
67
}
53
68
}
54
69
0 commit comments