14
14
import org .slf4j .Logger ;
15
15
import org .slf4j .LoggerFactory ;
16
16
17
- import java .io .File ;
18
17
import java .lang .foreign .MemorySegment ;
19
18
import java .lang .foreign .SegmentScope ;
20
- import java .net .URI ;
21
- import java .net .URISyntaxException ;
22
- import java .nio .file .Paths ;
23
19
import java .util .List ;
24
20
import java .util .function .Consumer ;
25
21
@@ -41,22 +37,27 @@ public static boolean isAvailable() {
41
37
}
42
38
43
39
@ Override
44
- public void showTrayIcon (URI uri , Runnable runnable , String s ) throws TrayMenuException {
45
- indicator = app_indicator_new (MemoryAllocator .ALLOCATE_FOR ("org.cryptomator.Cryptomator" ),
46
- MemoryAllocator .ALLOCATE_FOR (getAbsolutePath (getPathString (uri ))),
47
- APP_INDICATOR_CATEGORY_APPLICATION_STATUS ());
40
+ public void showTrayIcon (Consumer <TrayIconLoader > iconLoader , Runnable runnable , String s ) throws TrayMenuException {
41
+ TrayIconLoader .FreedesktopIconName callback = this ::showTrayIconWithSVG ;
42
+ iconLoader .accept (callback );
48
43
gtk_widget_show_all (menu );
49
44
app_indicator_set_menu (indicator , menu );
50
45
app_indicator_set_status (indicator , APP_INDICATOR_STATUS_ACTIVE ());
51
46
}
52
47
48
+ private void showTrayIconWithSVG (String s ) {
49
+ indicator = app_indicator_new (MemoryAllocator .ALLOCATE_FOR ("org.cryptomator.Cryptomator" ),
50
+ MemoryAllocator .ALLOCATE_FOR (s ),
51
+ APP_INDICATOR_CATEGORY_APPLICATION_STATUS ());
52
+ }
53
+
53
54
@ Override
54
55
public void updateTrayIcon (Consumer <TrayIconLoader > iconLoader ) {
55
- TrayIconLoader .FreedesktopIconName callback = this ::updateTrayIconCallback ;
56
- iconLoader .load (callback );
56
+ TrayIconLoader .FreedesktopIconName callback = this ::updateTrayIconWithSVG ;
57
+ iconLoader .accept (callback );
57
58
}
58
59
59
- private void updateTrayIconCallback (String s ) {
60
+ private void updateTrayIconWithSVG (String s ) {
60
61
app_indicator_set_icon (indicator , MemoryAllocator .ALLOCATE_FOR (s ));
61
62
}
62
63
@@ -102,22 +103,4 @@ private void addChildren(MemorySegment menu, List<TrayMenuItem> items) {
102
103
gtk_widget_show_all (menu );
103
104
}
104
105
}
105
-
106
- private String getAbsolutePath (String iconName ) {
107
- var res = getClass ().getClassLoader ().getResource (iconName );
108
- if (null == res ) {
109
- throw new IllegalArgumentException ("Icon '" + iconName + "' cannot be found in resource folder" );
110
- }
111
- File file = null ;
112
- try {
113
- file = Paths .get (res .toURI ()).toFile ();
114
- } catch (URISyntaxException e ) {
115
- throw new IllegalArgumentException ("Icon '" + iconName + "' cannot be converted to file" , e );
116
- }
117
- return file .getAbsolutePath ();
118
- }
119
-
120
- private String getPathString (URI uri ) {
121
- return uri .getPath ().substring (1 );
122
- }
123
106
}
0 commit comments