diff --git a/src/dorkbox/systemTray/nativeUI/GtkBaseMenuItem.java b/src/dorkbox/systemTray/nativeUI/GtkBaseMenuItem.java index fcc230b..e1382a6 100644 --- a/src/dorkbox/systemTray/nativeUI/GtkBaseMenuItem.java +++ b/src/dorkbox/systemTray/nativeUI/GtkBaseMenuItem.java @@ -22,12 +22,12 @@ import com.sun.jna.Pointer; import dorkbox.systemTray.jna.linux.Gobject; import dorkbox.systemTray.jna.linux.Gtk; import dorkbox.systemTray.peer.EntryPeer; -import dorkbox.systemTray.util.ImageUtils; +import dorkbox.systemTray.util.ImageResizeUtil; abstract class GtkBaseMenuItem implements EntryPeer { // these are necessary BECAUSE GTK menus look funky as hell when there are some menu entries WITH icons and some WITHOUT - private static File transparentIcon = null; + private static final File transparentIcon = ImageResizeUtil.getTransparentImage(); private volatile boolean hasLegitImage = true; // these have to be volatile, because they can be changed from any thread @@ -38,11 +38,6 @@ class GtkBaseMenuItem implements EntryPeer { GtkBaseMenuItem(final Pointer _native) { this._native = _native; - - // cannot be done in a static initializer, because the tray icon size might not yet have been determined - if (transparentIcon == null) { - transparentIcon = ImageUtils.getTransparentImage(ImageUtils.ENTRY_SIZE); - } } public diff --git a/src/dorkbox/systemTray/nativeUI/_AppIndicatorNativeTray.java b/src/dorkbox/systemTray/nativeUI/_AppIndicatorNativeTray.java index 34e3438..85785cb 100644 --- a/src/dorkbox/systemTray/nativeUI/_AppIndicatorNativeTray.java +++ b/src/dorkbox/systemTray/nativeUI/_AppIndicatorNativeTray.java @@ -28,7 +28,7 @@ import dorkbox.systemTray.jna.linux.AppIndicator; import dorkbox.systemTray.jna.linux.AppIndicatorInstanceStruct; import dorkbox.systemTray.jna.linux.Gobject; import dorkbox.systemTray.jna.linux.Gtk; -import dorkbox.systemTray.util.ImageUtils; +import dorkbox.systemTray.util.ImageResizeUtil; /** * Class for handling all system tray interactions. @@ -169,7 +169,6 @@ class _AppIndicatorNativeTray extends Tray implements NativeUI { if (!isActive) { isActive = true; - AppIndicator.app_indicator_set_status(appIndicator, AppIndicator.STATUS_ACTIVE); } } @@ -220,9 +219,10 @@ class _AppIndicatorNativeTray extends Tray implements NativeUI { @Override public void run() { - // we initialize with a blank image - File image = ImageUtils.getTransparentImage(ImageUtils.ENTRY_SIZE); String id = System.nanoTime() + "DBST"; + + // we initialize with a blank image. Throws RuntimeException if not possible (this should never happen!) + File image = ImageResizeUtil.getTransparentImage(); // tiny size is OK because we will be replacing this image. appIndicator = AppIndicator.app_indicator_new(id, image.getAbsolutePath(), AppIndicator.CATEGORY_APPLICATION_STATUS); } }); @@ -232,10 +232,10 @@ class _AppIndicatorNativeTray extends Tray implements NativeUI { bind(gtkMenu, null, systemTray); } - // https://bugs.launchpad.net/indicator-application/+bug/527458/comments/12 @Override protected void setTooltip_(final String tooltipText) { + // https://bugs.launchpad.net/indicator-application/+bug/527458/comments/12 } @Override diff --git a/src/dorkbox/systemTray/nativeUI/_AwtTray.java b/src/dorkbox/systemTray/nativeUI/_AwtTray.java index 77b4b7e..65dd19d 100644 --- a/src/dorkbox/systemTray/nativeUI/_AwtTray.java +++ b/src/dorkbox/systemTray/nativeUI/_AwtTray.java @@ -64,8 +64,6 @@ class _AwtTray extends Tray implements NativeUI { "type and configuration"); } - _AwtTray.this.tray = SystemTray.getSystemTray(); - // we override various methods, because each tray implementation is SLIGHTLY different. This allows us customization. final AwtMenu awtMenu = new AwtMenu(null) { @Override @@ -75,6 +73,10 @@ class _AwtTray extends Tray implements NativeUI { @Override public void run() { + if (tray == null) { + tray = SystemTray.getSystemTray(); + } + boolean enabled = menuItem.getEnabled(); if (OS.isMacOsX()) { @@ -138,6 +140,10 @@ class _AwtTray extends Tray implements NativeUI { @Override public void run() { + if (tray == null) { + tray = SystemTray.getSystemTray(); + } + // stupid java won't scale it right away, so we have to do this twice to get the correct size final Image trayImage = new ImageIcon(imageFile.getAbsolutePath()).getImage(); trayImage.flush(); @@ -185,7 +191,10 @@ class _AwtTray extends Tray implements NativeUI { void run() { if (trayIcon != null) { trayIcon.setPopupMenu(null); - tray.remove(trayIcon); + if (tray != null) { + tray.remove(trayIcon); + } + trayIcon = null; } @@ -209,6 +218,10 @@ class _AwtTray extends Tray implements NativeUI { @Override public void run() { + if (tray == null) { + tray = SystemTray.getSystemTray(); + } + // don't want to matter which (setImage/setTooltip/setEnabled) is done first, and if the image/enabled is changed, we // want to make sure keep the tooltip text the same as before. if (trayIcon != null) {