Fix for UbuntuGnome (which has AppIndicators + gnome-shell). Code polish

This commit is contained in:
nathan 2016-12-26 01:17:46 +01:00
parent 48cde07ff5
commit 2e55b34ec8
8 changed files with 73 additions and 25 deletions

View File

@ -756,7 +756,7 @@ class SystemTray {
if (isJavaFxLoaded) {
if (isTrayType(trayType, TrayType.GtkStatusIcon)) {
// set a property so that GTK (if necessary) can set the name of the system tray icon
System.setProperty("SystemTray_GTK_SET_NAME", "true");
System.setProperty("SystemTray_SET_NAME", "true");
}
// This will initialize javaFX dispatch methods

View File

@ -237,7 +237,7 @@ class Extension {
}
// set a property so that GTK (if necessary) can set the name
System.setProperty("SystemTray_GTK_SET_NAME", "true");
System.setProperty("SystemTray_SET_NAME", "true");
// have to copy the extension over and enable it.
String userHome = System.getProperty("user.home");

View File

@ -239,6 +239,7 @@ class AppIndicator {
public static native AppIndicatorInstanceStruct app_indicator_new(String id, String icon_name, int category);
public static native void app_indicator_set_title(AppIndicatorInstanceStruct self, String title);
public static native void app_indicator_set_status(AppIndicatorInstanceStruct self, int status);
public static native void app_indicator_set_menu(AppIndicatorInstanceStruct self, Pointer menu);
public static native void app_indicator_set_icon(AppIndicatorInstanceStruct self, String icon_name);

View File

@ -246,6 +246,13 @@ class Gtk {
if (SystemTray.isJavaFxLoaded) {
if (!JavaFX.isEventThread()) {
try {
if (!blockUntilStarted.await(10, TimeUnit.SECONDS)) {
if (SystemTray.DEBUG) {
SystemTray.logger.error("Something is very wrong. The waitForStartup took longer than expected.",
new Exception(""));
}
}
// we have to WAIT until all events are done processing, OTHERWISE we have initialization issues
while (true) {
Thread.sleep(100);
@ -256,13 +263,6 @@ class Gtk {
}
}
}
if (!blockUntilStarted.await(10, TimeUnit.SECONDS)) {
if (SystemTray.DEBUG) {
SystemTray.logger.error("Something is very wrong. The waitForStartup took longer than expected.",
new Exception(""));
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
@ -271,6 +271,13 @@ class Gtk {
if (!Swt.isEventThread()) {
// we have to WAIT until all events are done processing, OTHERWISE we have initialization issues
try {
if (!blockUntilStarted.await(10, TimeUnit.SECONDS)) {
if (SystemTray.DEBUG) {
SystemTray.logger.error("Something is very wrong. The waitForStartup took longer than expected.",
new Exception(""));
}
}
while (true) {
Thread.sleep(100);
@ -280,19 +287,19 @@ class Gtk {
}
}
}
if (!blockUntilStarted.await(10, TimeUnit.SECONDS)) {
if (SystemTray.DEBUG) {
SystemTray.logger.error("Something is very wrong. The waitForStartup took longer than expected.",
new Exception(""));
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} else {
try {
if (!blockUntilStarted.await(10, TimeUnit.SECONDS)) {
if (SystemTray.DEBUG) {
SystemTray.logger.error("Something is very wrong. The waitForStartup took longer than expected.",
new Exception(""));
}
}
// we have to WAIT until all events are done processing, OTHERWISE we have initialization issues
while (true) {
Thread.sleep(100);
@ -303,13 +310,6 @@ class Gtk {
}
}
}
if (!blockUntilStarted.await(10, TimeUnit.SECONDS)) {
if (SystemTray.DEBUG) {
SystemTray.logger.error("Something is very wrong. The waitForStartup took longer than expected.",
new Exception(""));
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}

View File

@ -209,6 +209,29 @@ class _AppIndicatorNativeTray extends Tray implements NativeUI {
Gtk.waitForStartup();
if (System.getProperty("SystemTray_SET_NAME", "false").equals("true")) {
Gtk.dispatch(new Runnable() {
@Override
public
void run() {
// by default, the title/name of the tray icon is "java". We are the only java-based tray icon, so we just use that.
// If you change "SystemTray" to something else, make sure to change it in extension.js as well
// default is to show the indicator
AppIndicator.app_indicator_set_status(appIndicator, AppIndicator.STATUS_ACTIVE);
// can cause
// GLib-GIO-CRITICAL **: g_dbus_connection_emit_signal: assertion 'object_path != NULL && g_variant_is_object_path (object_path)' failed
// Gdk-CRITICAL **: IA__gdk_window_thaw_toplevel_updates_libgtk_only: assertion 'private->update_and_descendants_freeze_count > 0' failed
// necessary for gnome icon detection/placement because we move tray icons around by title. This is hardcoded
// in extension.js, so don't change it
AppIndicator.app_indicator_set_title(appIndicator, "SystemTray");
}
});
}
bind(gtkMenu, null, systemTray);
}

View File

@ -196,7 +196,7 @@ class _GtkStatusIconNativeTray extends Tray implements NativeUI {
// BUT this is REQUIRED when running JavaFX or Gnome For unknown reasons, the title isn't pushed to GTK, so our
// gnome-shell extension cannot see our tray icon -- so naturally, it won't move it to the "top" area and
// we appear broken.
if (System.getProperty("SystemTray_GTK_SET_NAME", "false").equals("true")) {
if (System.getProperty("SystemTray_SET_NAME", "false").equals("true")) {
Gtk.gtk_status_icon_set_name(trayIcon, "SystemTray");
}
}

View File

@ -272,6 +272,30 @@ class _AppIndicatorTray extends Tray implements SwingUI {
bind(swingMenu, null, systemTray);
}
});
if (System.getProperty("SystemTray_SET_NAME", "false").equals("true")) {
Gtk.dispatch(new Runnable() {
@Override
public
void run() {
// by default, the title/name of the tray icon is "java". We are the only java-based tray icon, so we just use that.
// If you change "SystemTray" to something else, make sure to change it in extension.js as well
// default is to show the indicator
AppIndicator.app_indicator_set_status(appIndicator, AppIndicator.STATUS_ACTIVE);
// can cause
// GLib-GIO-CRITICAL **: g_dbus_connection_emit_signal: assertion 'object_path != NULL && g_variant_is_object_path (object_path)' failed
// Gdk-CRITICAL **: IA__gdk_window_thaw_toplevel_updates_libgtk_only: assertion 'private->update_and_descendants_freeze_count > 0' failed
// necessary for gnome icon detection/placement because we move tray icons around by title. This is hardcoded
// in extension.js, so don't change it
AppIndicator.app_indicator_set_title(appIndicator, "SystemTray");
}
});
}
}
private

View File

@ -118,7 +118,7 @@ class _GtkStatusIconTray extends Tray implements SwingUI {
// BUT this is REQUIRED when running JavaFX or Gnome For unknown reasons, the title isn't pushed to GTK, so our
// gnome-shell extension cannot see our tray icon -- so naturally, it won't move it to the "top" area and
// we appear broken.
if (System.getProperty("SystemTray_GTK_SET_NAME", "false").equals("true")) {
if (System.getProperty("SystemTray_SET_NAME", "false").equals("true")) {
Gtk.gtk_status_icon_set_name(trayIcon, "SystemTray");
}
}