1414import org .slf4j .Logger ;
1515import org .slf4j .LoggerFactory ;
1616
17- import java .io .File ;
1817import java .lang .foreign .MemorySegment ;
1918import java .lang .foreign .SegmentScope ;
20- import java .net .URI ;
21- import java .net .URISyntaxException ;
22- import java .nio .file .Paths ;
2319import java .util .List ;
2420import java .util .function .Consumer ;
2521
@@ -41,22 +37,27 @@ public static boolean isAvailable() {
4137 }
4238
4339 @ 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 );
4843 gtk_widget_show_all (menu );
4944 app_indicator_set_menu (indicator , menu );
5045 app_indicator_set_status (indicator , APP_INDICATOR_STATUS_ACTIVE ());
5146 }
5247
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+
5354 @ Override
5455 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 );
5758 }
5859
59- private void updateTrayIconCallback (String s ) {
60+ private void updateTrayIconWithSVG (String s ) {
6061 app_indicator_set_icon (indicator , MemoryAllocator .ALLOCATE_FOR (s ));
6162 }
6263
@@ -102,22 +103,4 @@ private void addChildren(MemorySegment menu, List<TrayMenuItem> items) {
102103 gtk_widget_show_all (menu );
103104 }
104105 }
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- }
123106}
0 commit comments