1010import org .cryptomator .integrations .tray .TrayMenuController ;
1111import org .cryptomator .integrations .tray .TrayMenuException ;
1212import org .cryptomator .integrations .tray .TrayMenuItem ;
13+ import org .cryptomator .linux .util .CheckUtil ;
1314import org .purejava .appindicator .AppIndicator ;
1415import org .purejava .appindicator .GCallback ;
1516import org .purejava .appindicator .GObject ;
@@ -32,7 +33,7 @@ public class AppindicatorTrayMenuController implements TrayMenuController {
3233
3334 private static final Arena ARENA = Arena .global ();
3435 private MemorySegment indicator ;
35- private MemorySegment menu = Gtk . newMenu () ;
36+ private MemorySegment menu ;
3637
3738 @ CheckAvailability
3839 public static boolean isAvailable () {
@@ -41,6 +42,7 @@ public static boolean isAvailable() {
4142
4243 @ Override
4344 public void showTrayIcon (Consumer <TrayIconLoader > iconLoader , Runnable runnable , String s ) throws TrayMenuException {
45+ menu = Gtk .newMenu ();
4446 TrayIconLoader .FreedesktopIconName callback = this ::showTrayIconWithSVG ;
4547 iconLoader .accept (callback );
4648 Gtk .widgetShowAll (menu );
@@ -71,11 +73,13 @@ public void updateTrayIcon(Consumer<TrayIconLoader> iconLoader) {
7173 }
7274
7375 private void updateTrayIconWithSVG (String iconName ) {
76+ CheckUtil .checkState (indicator != null , "Appindicator is not setup. Call showTrayIcon(...) first." );
7477 AppIndicator .setIcon (indicator , iconName );
7578 }
7679
7780 @ Override
7881 public void updateTrayMenu (List <TrayMenuItem > items ) throws TrayMenuException {
82+ CheckUtil .checkState (indicator != null , "Appindicator is not setup. Call showTrayIcon(...) first." );
7983 menu = Gtk .newMenu ();
8084 addChildren (menu , items );
8185 Gtk .widgetShowAll (menu );
0 commit comments