diff --git a/src/dorkbox/util/tray/SystemTray.java b/src/dorkbox/util/tray/SystemTray.java index 5646d5f..ea35dd2 100644 --- a/src/dorkbox/util/tray/SystemTray.java +++ b/src/dorkbox/util/tray/SystemTray.java @@ -78,7 +78,6 @@ class SystemTray { } if (OS.isLinux()) { - GtkSupport.init(); if (GtkSupport.isSupported) { // quick check, because we know that unity uses app-indicator. Maybe REALLY old versions do not. We support 14.04 LTE at least String getenv = System.getenv("XDG_CURRENT_DESKTOP"); diff --git a/src/dorkbox/util/tray/linux/AppIndicatorTray.java b/src/dorkbox/util/tray/linux/AppIndicatorTray.java index 9a7a1c4..4f431c3 100644 --- a/src/dorkbox/util/tray/linux/AppIndicatorTray.java +++ b/src/dorkbox/util/tray/linux/AppIndicatorTray.java @@ -101,6 +101,7 @@ class AppIndicatorTray extends SystemTray { libgtk.gdk_threads_leave(); + GtkSupport.startGui(); this.active = true; } @@ -133,12 +134,13 @@ class AppIndicatorTray extends SystemTray { } this.connectionStatusItem = null; - GtkSupport.shutdownGTK(); + GtkSupport.shutdownGui(); libgtk.gdk_threads_leave(); super.removeTray(); } + @SuppressWarnings("Duplicates") @Override public void setStatus(String infoString, String iconName) { @@ -162,6 +164,7 @@ class AppIndicatorTray extends SystemTray { /** * Will add a new menu entry, or update one if it already exists */ + @SuppressWarnings("Duplicates") @Override public void addMenuEntry(String menuText, final SystemTrayMenuAction callback) { @@ -213,6 +216,7 @@ class AppIndicatorTray extends SystemTray { public void updateMenuEntry(String origMenuText, String newMenuText, final SystemTrayMenuAction newCallback) { synchronized (this.menuEntries) { + @SuppressWarnings("Duplicates") MenuEntry menuEntry = this.menuEntries.get(origMenuText); if (menuEntry != null) { diff --git a/src/dorkbox/util/tray/linux/GtkSystemTray.java b/src/dorkbox/util/tray/linux/GtkSystemTray.java index c947a1b..2ccd575 100644 --- a/src/dorkbox/util/tray/linux/GtkSystemTray.java +++ b/src/dorkbox/util/tray/linux/GtkSystemTray.java @@ -60,11 +60,14 @@ class GtkSystemTray extends SystemTray { void createTray(String iconName) { libgtk.gdk_threads_enter(); - this.menu = libgtk.gtk_menu_new(); - final Pointer trayIcon = libgtk.gtk_status_icon_new(); + libgtk.gtk_status_icon_set_title(trayIcon, "SystemTray@Dorkbox"); + libgtk.gtk_status_icon_set_tooltip(trayIcon, "SystemTray@Dorkbox"); + this.trayIcon = trayIcon; + libgtk.gtk_status_icon_set_from_file(trayIcon, iconPath(iconName)); + this.menu = libgtk.gtk_menu_new(); this.gtkCallback = new Gobject.GEventCallback() { @Override public @@ -75,19 +78,14 @@ class GtkSystemTray extends SystemTray { } } }; - libgobject.g_signal_connect_data(trayIcon, "button_press_event", gtkCallback, menu, null, 0); -// This is unreliable to use in our gnome-shell notification hook, because of race conditions, it will only sometimes be correct -// libgtk.gtk_status_icon_set_title(trayIcon, "something"); - - libgtk.gtk_status_icon_set_tooltip(trayIcon, this.appName); libgtk.gtk_status_icon_set_visible(trayIcon, true); - this.trayIcon = trayIcon; - libgtk.gdk_threads_leave(); + System.err.println("POW2"); + GtkSupport.startGui(); this.active = true; } @@ -111,7 +109,7 @@ class GtkSystemTray extends SystemTray { this.widgets.clear(); // unrefs the children too - libgobject.g_object_unref(this.menu); + // libgobject.g_object_unref(this.menu); shouldn't do this because of how we use it this.menu = null; synchronized (this.menuEntries) { @@ -120,7 +118,7 @@ class GtkSystemTray extends SystemTray { this.connectionStatusItem = null; - GtkSupport.shutdownGTK(); + GtkSupport.shutdownGui(); libgtk.gdk_threads_leave(); super.removeTray(); diff --git a/src/dorkbox/util/tray/linux/extension.js b/src/dorkbox/util/tray/linux/extension.js index c0c58b7..5031727 100644 --- a/src/dorkbox/util/tray/linux/extension.js +++ b/src/dorkbox/util/tray/linux/extension.js @@ -15,12 +15,12 @@ * limitations under the License. * * - * This is heavily modified from an online email from Vladimir Khrustalev. + * This is heavily modified from an online email/pastebin by Vladimir Khrustalev. * - * The source material is NOT GPLx/MIT/BSD/Apache/etc, because those licenses - * were not specified in accordance with those license requirements (there - * was no license specified or implied). As such, this is to be considered as - * released by the original sources as public domain. + * The source material was not licensed explicitly or implicitly, as such, + * this is considered as released by the original sources as public domain. + * + * Vladimir's email address is unknown. */ const Clutter = imports.gi.Clutter; @@ -35,6 +35,7 @@ const Meta = imports.gi.Meta; const Mainloop = imports.mainloop; const NotificationDaemon = imports.ui.notificationDaemon; +let APP_NAME = "SystemTray@Dorkbox"; let trayAddedId = 0; let orig_onTrayIconAdded; @@ -138,8 +139,7 @@ function installHook() { let icon = source.trayIcon; - // we could set the title in java, HOWEVER because of race conditions, it's not consistent. So we check for 'java' - if (icon.title !== "java") { + if (icon.title !== APP_NAME) { continue; } @@ -155,8 +155,7 @@ function installHook() { let button = notificationDaemon._iconBox.get_child_at_index(i); let icon = button.child; - // we could set the title in java, HOWEVER because of race conditions, it's not consistent. So we check for 'java' - if (icon.title !== "java") { + if (icon.title !== APP_NAME) { continue; } @@ -173,14 +172,13 @@ function installHook() { } function getSourceHook (title, pid, ndata, sender, trayIcon) { - // we could set the title in java, HOWEVER because of race conditions, it's not consistent. So we check for 'java' - if (trayIcon && title === "java") { + if (trayIcon && title === APP_NAME) { //global.log("create source"); onTrayIconAdded(this, trayIcon); return null; } - return getSource(title, pid, ndata, sender, trayIcon); + return orig_getSource(title, pid, ndata, sender, trayIcon); } // this is the hook that lets us only add ourselves. @@ -192,8 +190,7 @@ function onTrayIconAdded(o, icon) { return; } - // we could set the title in java, HOWEVER because of race conditions, it's not consistent. So we check for 'java' - if (icon.title !== "java") { + if (icon.title !== APP_NAME) { orig_onTrayIconAdded(o, icon); return; } @@ -253,8 +250,7 @@ function onTrayIconAdded(o, icon) { function onTrayIconRemoved(o, icon) { //global.log("removing tray icon " + icon.title); - // we could set the title in java, HOWEVER because of race conditions, it's not consistent. So we check for 'java' - if (icon.title !== "java") { + if (icon.title !== APP_NAME) { orig_onTrayIconRemoved(o, icon); return; }