forked from dorkbox/SystemTray
Code cleanup. Also starts the GTK main loop AFTER the tray icon is created. This is so the title can be accurately set BEFORE it gets added to the screen. This was particularly a problem for gnome-shell (which was a PITA to begin with).
This commit is contained in:
parent
c8fac55967
commit
d131953f1f
@ -78,7 +78,6 @@ class SystemTray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (OS.isLinux()) {
|
if (OS.isLinux()) {
|
||||||
GtkSupport.init();
|
|
||||||
if (GtkSupport.isSupported) {
|
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
|
// 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");
|
String getenv = System.getenv("XDG_CURRENT_DESKTOP");
|
||||||
|
@ -101,6 +101,7 @@ class AppIndicatorTray extends SystemTray {
|
|||||||
|
|
||||||
libgtk.gdk_threads_leave();
|
libgtk.gdk_threads_leave();
|
||||||
|
|
||||||
|
GtkSupport.startGui();
|
||||||
this.active = true;
|
this.active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,12 +134,13 @@ class AppIndicatorTray extends SystemTray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.connectionStatusItem = null;
|
this.connectionStatusItem = null;
|
||||||
GtkSupport.shutdownGTK();
|
GtkSupport.shutdownGui();
|
||||||
|
|
||||||
libgtk.gdk_threads_leave();
|
libgtk.gdk_threads_leave();
|
||||||
super.removeTray();
|
super.removeTray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void setStatus(String infoString, String iconName) {
|
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
|
* Will add a new menu entry, or update one if it already exists
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void addMenuEntry(String menuText, final SystemTrayMenuAction callback) {
|
void addMenuEntry(String menuText, final SystemTrayMenuAction callback) {
|
||||||
@ -213,6 +216,7 @@ class AppIndicatorTray extends SystemTray {
|
|||||||
public
|
public
|
||||||
void updateMenuEntry(String origMenuText, String newMenuText, final SystemTrayMenuAction newCallback) {
|
void updateMenuEntry(String origMenuText, String newMenuText, final SystemTrayMenuAction newCallback) {
|
||||||
synchronized (this.menuEntries) {
|
synchronized (this.menuEntries) {
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
MenuEntry menuEntry = this.menuEntries.get(origMenuText);
|
MenuEntry menuEntry = this.menuEntries.get(origMenuText);
|
||||||
|
|
||||||
if (menuEntry != null) {
|
if (menuEntry != null) {
|
||||||
|
@ -60,11 +60,14 @@ class GtkSystemTray extends SystemTray {
|
|||||||
void createTray(String iconName) {
|
void createTray(String iconName) {
|
||||||
libgtk.gdk_threads_enter();
|
libgtk.gdk_threads_enter();
|
||||||
|
|
||||||
this.menu = libgtk.gtk_menu_new();
|
|
||||||
|
|
||||||
final Pointer trayIcon = libgtk.gtk_status_icon_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));
|
libgtk.gtk_status_icon_set_from_file(trayIcon, iconPath(iconName));
|
||||||
|
|
||||||
|
this.menu = libgtk.gtk_menu_new();
|
||||||
this.gtkCallback = new Gobject.GEventCallback() {
|
this.gtkCallback = new Gobject.GEventCallback() {
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
@ -75,19 +78,14 @@ class GtkSystemTray extends SystemTray {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
libgobject.g_signal_connect_data(trayIcon, "button_press_event", gtkCallback, menu, null, 0);
|
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);
|
libgtk.gtk_status_icon_set_visible(trayIcon, true);
|
||||||
|
|
||||||
this.trayIcon = trayIcon;
|
|
||||||
|
|
||||||
libgtk.gdk_threads_leave();
|
libgtk.gdk_threads_leave();
|
||||||
|
|
||||||
|
System.err.println("POW2");
|
||||||
|
GtkSupport.startGui();
|
||||||
this.active = true;
|
this.active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +109,7 @@ class GtkSystemTray extends SystemTray {
|
|||||||
this.widgets.clear();
|
this.widgets.clear();
|
||||||
|
|
||||||
// unrefs the children too
|
// 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;
|
this.menu = null;
|
||||||
|
|
||||||
synchronized (this.menuEntries) {
|
synchronized (this.menuEntries) {
|
||||||
@ -120,7 +118,7 @@ class GtkSystemTray extends SystemTray {
|
|||||||
|
|
||||||
this.connectionStatusItem = null;
|
this.connectionStatusItem = null;
|
||||||
|
|
||||||
GtkSupport.shutdownGTK();
|
GtkSupport.shutdownGui();
|
||||||
|
|
||||||
libgtk.gdk_threads_leave();
|
libgtk.gdk_threads_leave();
|
||||||
super.removeTray();
|
super.removeTray();
|
||||||
|
@ -15,12 +15,12 @@
|
|||||||
* limitations under the License.
|
* 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
|
* The source material was not licensed explicitly or implicitly, as such,
|
||||||
* were not specified in accordance with those license requirements (there
|
* this is considered as released by the original sources as public domain.
|
||||||
* was no license specified or implied). As such, this is to be considered as
|
*
|
||||||
* released by the original sources as public domain.
|
* Vladimir's email address is unknown.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Clutter = imports.gi.Clutter;
|
const Clutter = imports.gi.Clutter;
|
||||||
@ -35,6 +35,7 @@ const Meta = imports.gi.Meta;
|
|||||||
const Mainloop = imports.mainloop;
|
const Mainloop = imports.mainloop;
|
||||||
const NotificationDaemon = imports.ui.notificationDaemon;
|
const NotificationDaemon = imports.ui.notificationDaemon;
|
||||||
|
|
||||||
|
let APP_NAME = "SystemTray@Dorkbox";
|
||||||
let trayAddedId = 0;
|
let trayAddedId = 0;
|
||||||
let orig_onTrayIconAdded;
|
let orig_onTrayIconAdded;
|
||||||
|
|
||||||
@ -138,8 +139,7 @@ function installHook() {
|
|||||||
|
|
||||||
let icon = source.trayIcon;
|
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 !== APP_NAME) {
|
||||||
if (icon.title !== "java") {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,8 +155,7 @@ function installHook() {
|
|||||||
let button = notificationDaemon._iconBox.get_child_at_index(i);
|
let button = notificationDaemon._iconBox.get_child_at_index(i);
|
||||||
let icon = button.child;
|
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 !== APP_NAME) {
|
||||||
if (icon.title !== "java") {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,14 +172,13 @@ function installHook() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSourceHook (title, pid, ndata, sender, trayIcon) {
|
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 === APP_NAME) {
|
||||||
if (trayIcon && title === "java") {
|
|
||||||
//global.log("create source");
|
//global.log("create source");
|
||||||
onTrayIconAdded(this, trayIcon);
|
onTrayIconAdded(this, trayIcon);
|
||||||
return null;
|
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.
|
// this is the hook that lets us only add ourselves.
|
||||||
@ -192,8 +190,7 @@ function onTrayIconAdded(o, icon) {
|
|||||||
return;
|
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 !== APP_NAME) {
|
||||||
if (icon.title !== "java") {
|
|
||||||
orig_onTrayIconAdded(o, icon);
|
orig_onTrayIconAdded(o, icon);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -253,8 +250,7 @@ function onTrayIconAdded(o, icon) {
|
|||||||
function onTrayIconRemoved(o, icon) {
|
function onTrayIconRemoved(o, icon) {
|
||||||
//global.log("removing tray icon " + icon.title);
|
//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 !== APP_NAME) {
|
||||||
if (icon.title !== "java") {
|
|
||||||
orig_onTrayIconRemoved(o, icon);
|
orig_onTrayIconRemoved(o, icon);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user