Added ability to debug failures during system-tray detection

This commit is contained in:
nathan 2016-04-24 17:30:33 +02:00
parent d00c99fb4f
commit 4eb2e89d38

View File

@ -33,7 +33,6 @@ import java.io.BufferedReader;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -80,6 +79,12 @@ class SystemTray {
*/ */
public static boolean ENABLE_SHUTDOWN_HOOK = true; public static boolean ENABLE_SHUTDOWN_HOOK = true;
@Property
/**
* This property is provided for debugging any errors in the logic used to determine the system-tray type.
*/
public static boolean DEBUG = false;
private static volatile SystemTray systemTray = null; private static volatile SystemTray systemTray = null;
static boolean isKDE = false; static boolean isKDE = false;
@ -144,37 +149,56 @@ class SystemTray {
if (OS.isLinux()) { if (OS.isLinux()) {
// see: https://askubuntu.com/questions/72549/how-to-determine-which-window-manager-is-running // see: https://askubuntu.com/questions/72549/how-to-determine-which-window-manager-is-running
// For funsies, SyncThing did a LOT of work on compatibility (unfortunate for us) in python.
// https://github.com/syncthing/syncthing-gtk/blob/b7a3bc00e3bb6d62365ae62b5395370f3dcc7f55/syncthing_gtk/statusicon.py
// 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 XDG = System.getenv("XDG_CURRENT_DESKTOP"); String XDG = System.getenv("XDG_CURRENT_DESKTOP");
if ("Unity".equalsIgnoreCase(XDG)) { if ("Unity".equalsIgnoreCase(XDG)) {
try { try {
trayType = AppIndicatorTray.class; trayType = AppIndicatorTray.class;
} catch (Throwable ignored) { } catch (Throwable e) {
if (DEBUG) {
e.printStackTrace();
}
} }
} }
else if ("XFCE".equalsIgnoreCase(XDG)) { else if ("XFCE".equalsIgnoreCase(XDG)) {
try { try {
trayType = AppIndicatorTray.class; trayType = AppIndicatorTray.class;
} catch (Throwable ignored) { } catch (Throwable e) {
if (DEBUG) {
e.printStackTrace();
}
// we can fail on AppIndicator, so this is the fallback // we can fail on AppIndicator, so this is the fallback
//noinspection EmptyCatchBlock //noinspection EmptyCatchBlock
try { try {
trayType = GtkSystemTray.class; trayType = GtkSystemTray.class;
} catch (Throwable i) { } catch (Throwable e1) {
if (DEBUG) {
e1.printStackTrace();
}
} }
} }
} }
else if ("LXDE".equalsIgnoreCase(XDG)) { else if ("LXDE".equalsIgnoreCase(XDG)) {
try { try {
trayType = GtkSystemTray.class; trayType = GtkSystemTray.class;
} catch (Throwable ignored) { } catch (Throwable e) {
if (DEBUG) {
e.printStackTrace();
}
} }
} }
else if ("KDE".equalsIgnoreCase(XDG)) { else if ("KDE".equalsIgnoreCase(XDG)) {
isKDE = true; isKDE = true;
try { try {
trayType = AppIndicatorTray.class; trayType = AppIndicatorTray.class;
} catch (Throwable ignored) { } catch (Throwable e) {
if (DEBUG) {
e.printStackTrace();
}
} }
} }
else if ("GNOME".equalsIgnoreCase(XDG)) { else if ("GNOME".equalsIgnoreCase(XDG)) {
@ -184,24 +208,33 @@ class SystemTray {
if ("cinnamon".equalsIgnoreCase(GDM)) { if ("cinnamon".equalsIgnoreCase(GDM)) {
try { try {
trayType = GtkSystemTray.class; trayType = GtkSystemTray.class;
} catch (Throwable ignored) { } catch (Throwable e) {
if (DEBUG) {
e.printStackTrace();
}
} }
} }
else if ("gnome-classic".equalsIgnoreCase(GDM)) { else if ("gnome-classic".equalsIgnoreCase(GDM)) {
try { try {
trayType = GtkSystemTray.class; trayType = GtkSystemTray.class;
} catch (Throwable ignored) { } catch (Throwable e) {
if (DEBUG) {
e.printStackTrace();
}
} }
} }
else if ("gnome-fallback".equalsIgnoreCase(GDM)) { else if ("gnome-fallback".equalsIgnoreCase(GDM)) {
try { try {
trayType = GtkSystemTray.class; trayType = GtkSystemTray.class;
} catch (Throwable ignored) { } catch (Throwable e) {
if (DEBUG) {
e.printStackTrace();
}
} }
} }
// unknown exactly, install extension and go from there // is likely 'gnome', but it can also be unknown (or something completely different), install extension and go from there
if (trayType == null) { if (trayType == null) {
// if the "topicons" extension is installed, don't install us (because it will override what we do, where ours // if the "topicons" extension is installed, don't install us (because it will override what we do, where ours
// is more specialized - so it only modified our tray icon (instead of ALL tray icons) // is more specialized - so it only modified our tray icon (instead of ALL tray icons)
@ -222,7 +255,10 @@ class SystemTray {
GnomeShellExtension.install(logger, output); GnomeShellExtension.install(logger, output);
trayType = GtkSystemTray.class; trayType = GtkSystemTray.class;
} }
} catch (Throwable ignored) { } catch (Throwable e) {
if (DEBUG) {
e.printStackTrace();
}
trayType = null; trayType = null;
} }
} }
@ -261,7 +297,9 @@ class SystemTray {
trayType = AppIndicatorTray.class; trayType = AppIndicatorTray.class;
} catch (Throwable e) { } catch (Throwable e) {
logger.error("AppIndicator support detected, but unable to load the library. Falling back to GTK"); logger.error("AppIndicator support detected, but unable to load the library. Falling back to GTK");
e.printStackTrace(); if (DEBUG) {
e.printStackTrace();
}
} }
break; break;
} }
@ -276,12 +314,18 @@ class SystemTray {
} }
} }
} }
} catch (Throwable ignored) { } catch (Throwable e) {
if (DEBUG) {
e.printStackTrace();
}
} finally { } finally {
if (bin != null) { if (bin != null) {
try { try {
bin.close(); bin.close();
} catch (IOException ignored) { } catch (Throwable e) {
if (DEBUG) {
e.printStackTrace();
}
} }
} }
} }
@ -301,8 +345,11 @@ class SystemTray {
try { try {
java.awt.SystemTray.getSystemTray(); java.awt.SystemTray.getSystemTray();
trayType = SwingSystemTray.class; trayType = SwingSystemTray.class;
} catch (Throwable ignored) { } catch (Throwable e) {
logger.error("Maybe you should grant the AWTPermission `accessSystemTray` in the SecurityManager."); logger.error("Maybe you should grant the AWTPermission `accessSystemTray` in the SecurityManager.");
if (DEBUG) {
e.printStackTrace();
}
} }
} }
@ -330,7 +377,10 @@ class SystemTray {
trayType = GtkSystemTray.class; trayType = GtkSystemTray.class;
logger.warn("AppIndicator3 detected with GTK2, falling back to GTK2 system tray type. " + logger.warn("AppIndicator3 detected with GTK2, falling back to GTK2 system tray type. " +
"Please install libappindicator1 OR GTK3, for example: 'sudo apt-get install libappindicator1'"); "Please install libappindicator1 OR GTK3, for example: 'sudo apt-get install libappindicator1'");
} catch (Throwable ignored) { } catch (Throwable e) {
if (DEBUG) {
e.printStackTrace();
}
logger.error("AppIndicator3 detected with GTK2 and unable to fallback to using GTK2 system tray type." + logger.error("AppIndicator3 detected with GTK2 and unable to fallback to using GTK2 system tray type." +
"AppIndicator3 requires GTK3 to be fully functional, and while this will work -- the menu icons WILL " + "AppIndicator3 requires GTK3 to be fully functional, and while this will work -- the menu icons WILL " +
"NOT be visible." + "NOT be visible." +
@ -378,7 +428,10 @@ class SystemTray {
systemTray.shutdown(); systemTray.shutdown();
} }
}); });
} catch (Throwable ignored) { } catch (Throwable e) {
if (DEBUG) {
e.printStackTrace();
}
logger.error("Unable to insert shutdown hook into JavaFX. Please create an issue with your OS and Java " + logger.error("Unable to insert shutdown hook into JavaFX. Please create an issue with your OS and Java " +
"version so we may further investigate this issue."); "version so we may further investigate this issue.");
} }
@ -399,7 +452,10 @@ class SystemTray {
systemTray.shutdown(); systemTray.shutdown();
} }
}); });
} catch (Throwable ignored) { } catch (Throwable e) {
if (DEBUG) {
e.printStackTrace();
}
logger.error("Unable to insert shutdown hook into SWT. Please create an issue with your OS and Java " + logger.error("Unable to insert shutdown hook into SWT. Please create an issue with your OS and Java " +
"version so we may further investigate this issue."); "version so we may further investigate this issue.");
} }