Skip to content

Commit

Permalink
add checks before accessing instance variables in public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed Apr 18, 2024
1 parent 037be96 commit 401dce1
Showing 1 changed file with 5 additions and 1 deletion.
Expand Up @@ -10,6 +10,7 @@
import org.cryptomator.integrations.tray.TrayMenuController;
import org.cryptomator.integrations.tray.TrayMenuException;
import org.cryptomator.integrations.tray.TrayMenuItem;
import org.cryptomator.linux.util.CheckUtil;
import org.purejava.appindicator.AppIndicator;
import org.purejava.appindicator.GCallback;
import org.purejava.appindicator.GObject;
Expand All @@ -32,7 +33,7 @@ public class AppindicatorTrayMenuController implements TrayMenuController {

private static final Arena ARENA = Arena.global();
private MemorySegment indicator;
private MemorySegment menu = Gtk.newMenu();
private MemorySegment menu;

@CheckAvailability
public static boolean isAvailable() {
Expand All @@ -41,6 +42,7 @@ public static boolean isAvailable() {

@Override
public void showTrayIcon(Consumer<TrayIconLoader> iconLoader, Runnable runnable, String s) throws TrayMenuException {
menu = Gtk.newMenu();
TrayIconLoader.FreedesktopIconName callback = this::showTrayIconWithSVG;
iconLoader.accept(callback);
Gtk.widgetShowAll(menu);
Expand Down Expand Up @@ -71,11 +73,13 @@ public void updateTrayIcon(Consumer<TrayIconLoader> iconLoader) {
}

private void updateTrayIconWithSVG(String iconName) {
CheckUtil.checkState(indicator != null, "Appindicator is not setup. Call showTrayIcon(...) first.");
AppIndicator.setIcon(indicator, iconName);
}

@Override
public void updateTrayMenu(List<TrayMenuItem> items) throws TrayMenuException {
CheckUtil.checkState(indicator != null, "Appindicator is not setup. Call showTrayIcon(...) first.");
menu = Gtk.newMenu();
addChildren(menu, items);
Gtk.widgetShowAll(menu);
Expand Down

0 comments on commit 401dce1

Please sign in to comment.