1010import org .cryptomator .integrations .tray .TrayMenuController ;
1111import org .cryptomator .integrations .tray .TrayMenuException ;
1212import org .cryptomator .integrations .tray .TrayMenuItem ;
13+ import org .purejava .appindicator .AppIndicator ;
1314import org .purejava .appindicator .GCallback ;
14- import org .purejava .appindicator .NativeLibUtilities ;
15+ import org .purejava .appindicator .GObject ;
16+ import org .purejava .appindicator .Gtk ;
1517
1618import java .lang .foreign .Arena ;
1719import java .lang .foreign .MemorySegment ;
1820import java .util .List ;
19- import java .util .Optional ;
2021import java .util .function .Consumer ;
2122
22- import static org .purejava .appindicator .app_indicator_h .*;
23+ import static org .purejava .appindicator .app_indicator_h .APP_INDICATOR_CATEGORY_APPLICATION_STATUS ;
24+ import static org .purejava .appindicator .app_indicator_h .APP_INDICATOR_STATUS_ACTIVE ;
2325
2426@ Priority (1000 )
2527@ CheckAvailability
@@ -30,37 +32,35 @@ public class AppindicatorTrayMenuController implements TrayMenuController {
3032
3133 private static final Arena ARENA = Arena .global ();
3234 private MemorySegment indicator ;
33- private MemorySegment menu = gtk_menu_new ();
35+ private MemorySegment menu = Gtk . newMenu ();
3436
3537 @ CheckAvailability
3638 public static boolean isAvailable () {
37- return NativeLibUtilities . isLoadedNativeLib ();
39+ return AppIndicator . isLoaded ();
3840 }
3941
4042 @ Override
4143 public void showTrayIcon (Consumer <TrayIconLoader > iconLoader , Runnable runnable , String s ) throws TrayMenuException {
4244 TrayIconLoader .FreedesktopIconName callback = this ::showTrayIconWithSVG ;
4345 iconLoader .accept (callback );
44- gtk_widget_show_all (menu );
45- app_indicator_set_status (indicator , APP_INDICATOR_STATUS_ACTIVE ());
46+ Gtk . widgetShowAll (menu );
47+ AppIndicator . setStatus (indicator , APP_INDICATOR_STATUS_ACTIVE ());
4648 }
4749
48- private void showTrayIconWithSVG (String s ) {
49- try (var arena = Arena .ofConfined ()) {
50- var svgSourcePath = System .getProperty (SVG_SOURCE_PROPERTY );
51- // flatpak
52- if (svgSourcePath == null ) {
53- indicator = app_indicator_new (arena .allocateUtf8String (APP_INDICATOR_ID ),
54- arena .allocateUtf8String (s ),
55- APP_INDICATOR_CATEGORY_APPLICATION_STATUS ());
56- // AppImage and ppa
57- } else {
58- indicator = app_indicator_new_with_path (arena .allocateUtf8String (APP_INDICATOR_ID ),
59- arena .allocateUtf8String (s ),
60- APP_INDICATOR_CATEGORY_APPLICATION_STATUS (),
61- // find tray icons theme in mounted AppImage / installed on system by ppa
62- arena .allocateUtf8String (svgSourcePath ));
63- }
50+ private void showTrayIconWithSVG (String iconName ) {
51+ var svgSourcePath = System .getProperty (SVG_SOURCE_PROPERTY );
52+ // flatpak
53+ if (svgSourcePath == null ) {
54+ indicator = AppIndicator .newIndicator (APP_INDICATOR_ID ,
55+ iconName ,
56+ APP_INDICATOR_CATEGORY_APPLICATION_STATUS ());
57+ // AppImage and ppa
58+ } else {
59+ indicator = AppIndicator .newIndicatorWithPath (APP_INDICATOR_ID ,
60+ iconName ,
61+ APP_INDICATOR_CATEGORY_APPLICATION_STATUS (),
62+ // find tray icons theme in mounted AppImage / installed on system by ppa
63+ svgSourcePath );
6464 }
6565 }
6666
@@ -70,18 +70,16 @@ public void updateTrayIcon(Consumer<TrayIconLoader> iconLoader) {
7070 iconLoader .accept (callback );
7171 }
7272
73- private void updateTrayIconWithSVG (String s ) {
74- try (var arena = Arena .ofConfined ()) {
75- app_indicator_set_icon (indicator , arena .allocateUtf8String (s ));
76- }
73+ private void updateTrayIconWithSVG (String iconName ) {
74+ AppIndicator .setIcon (indicator , iconName );
7775 }
7876
7977 @ Override
8078 public void updateTrayMenu (List <TrayMenuItem > items ) throws TrayMenuException {
81- menu = gtk_menu_new ();
79+ menu = Gtk . newMenu ();
8280 addChildren (menu , items );
83- gtk_widget_show_all (menu );
84- app_indicator_set_menu (indicator , menu );
81+ Gtk . widgetShowAll (menu );
82+ AppIndicator . setMenu (indicator , menu );
8583 }
8684
8785 @ Override
@@ -93,30 +91,26 @@ private void addChildren(MemorySegment menu, List<TrayMenuItem> items) {
9391 for (var item : items ) {
9492 switch (item ) {
9593 case ActionItem a -> {
96- var gtkMenuItem = gtk_menu_item_new ();
97- try (var arena = Arena .ofConfined ()) {
98- gtk_menu_item_set_label (gtkMenuItem , arena .allocateUtf8String (a .title ()));
99- g_signal_connect_object (gtkMenuItem ,
100- arena .allocateUtf8String ("activate" ),
101- GCallback .allocate (new ActionItemCallback (a ), ARENA ),
102- menu ,
103- 0 );
104- }
105- gtk_menu_shell_append (menu , gtkMenuItem );
94+ var gtkMenuItem = Gtk .newMenuItem ();
95+ Gtk .menuItemSetLabel (gtkMenuItem , a .title ());
96+ GObject .signalConnectObject (gtkMenuItem ,
97+ "activate" ,
98+ GCallback .allocate (new ActionItemCallback (a ), ARENA ),
99+ menu ,
100+ 0 );
101+ Gtk .menuShellAppend (menu , gtkMenuItem );
106102 }
107103 case SeparatorItem _ -> {
108- var gtkSeparator = gtk_menu_item_new ();
109- gtk_menu_shell_append (menu , gtkSeparator );
104+ var gtkSeparator = Gtk . newMenuItem ();
105+ Gtk . menuShellAppend (menu , gtkSeparator );
110106 }
111107 case SubMenuItem s -> {
112- var gtkMenuItem = gtk_menu_item_new ();
113- var gtkSubmenu = gtk_menu_new ();
114- try (var arena = Arena .ofConfined ()) {
115- gtk_menu_item_set_label (gtkMenuItem , arena .allocateUtf8String (s .title ()));
116- }
108+ var gtkMenuItem = Gtk .newMenuItem ();
109+ var gtkSubmenu = Gtk .newMenu ();
110+ Gtk .menuItemSetLabel (gtkMenuItem , s .title ());
117111 addChildren (gtkSubmenu , s .items ());
118- gtk_menu_item_set_submenu (gtkMenuItem , gtkSubmenu );
119- gtk_menu_shell_append (menu , gtkMenuItem );
112+ Gtk . menuItemSetSubmenu (gtkMenuItem , gtkSubmenu );
113+ Gtk . menuShellAppend (menu , gtkMenuItem );
120114 }
121115 }
122116 }
0 commit comments