Code polish

This commit is contained in:
nathan 2016-09-26 02:44:36 +02:00
parent fb8c5c2378
commit ffb5657f61
6 changed files with 11 additions and 26 deletions

View File

@ -44,6 +44,7 @@ import dorkbox.systemTray.util.JavaFX;
import dorkbox.systemTray.util.Swt; import dorkbox.systemTray.util.Swt;
import dorkbox.systemTray.util.WindowsSystemTraySwing; import dorkbox.systemTray.util.WindowsSystemTraySwing;
import dorkbox.util.CacheUtil; import dorkbox.util.CacheUtil;
import dorkbox.util.IO;
import dorkbox.util.OS; import dorkbox.util.OS;
import dorkbox.util.Property; import dorkbox.util.Property;
import dorkbox.util.process.ShellProcessBuilder; import dorkbox.util.process.ShellProcessBuilder;
@ -58,7 +59,7 @@ class SystemTray {
public static final Logger logger = LoggerFactory.getLogger(SystemTray.class); public static final Logger logger = LoggerFactory.getLogger(SystemTray.class);
public static final int TYPE_AUTO_DETECT = 0; public static final int TYPE_AUTO_DETECT = 0;
public static final int TYPE_GTKSTATUSICON = 1; public static final int TYPE_GTK_STATUSICON = 1;
public static final int TYPE_APP_INDICATOR = 2; public static final int TYPE_APP_INDICATOR = 2;
public static final int TYPE_SWING = 3; public static final int TYPE_SWING = 3;
@ -98,11 +99,11 @@ class SystemTray {
@Property @Property
/** Forces the system tray to always choose GTK2 (even when GTK3 might be available). */ /** Forces the system tray to always choose GTK2 (even when GTK3 might be available). */
public static boolean FORCE_GTK2 = true; public static boolean FORCE_GTK2 = false;
@Property @Property
/** Forces the system tray detection to be Automatic (0), GTK (1), AppIndicator (2), or Swing (3). This is an advanced feature. */ /** Forces the system tray detection to be Automatic (0), GTK (1), AppIndicator (2), or Swing (3). This is an advanced feature. */
public static int FORCE_TRAY_TYPE = 1; public static int FORCE_TRAY_TYPE = 0;
@Property @Property
/** /**
@ -261,7 +262,7 @@ class SystemTray {
} }
} }
if (SystemTray.FORCE_TRAY_TYPE == SystemTray.TYPE_GTKSTATUSICON) { if (SystemTray.FORCE_TRAY_TYPE == SystemTray.TYPE_GTK_STATUSICON) {
try { try {
trayType = GtkSystemTray.class; trayType = GtkSystemTray.class;
} catch (Throwable e1) { } catch (Throwable e1) {
@ -527,13 +528,7 @@ class SystemTray {
break; break;
} }
} finally { } finally {
if (bin != null) { IO.closeQuietly(bin);
try {
bin.close();
} catch (Exception ignored) {
}
bin = null;
}
} }
} }
} }
@ -541,16 +536,6 @@ class SystemTray {
if (DEBUG) { if (DEBUG) {
logger.error("Error detecting gnome version", e); logger.error("Error detecting gnome version", e);
} }
} finally {
if (bin != null) {
try {
bin.close();
} catch (Throwable e) {
if (DEBUG) {
logger.error("Cannot close buffered reader", e);
}
}
}
} }
} }

View File

@ -45,7 +45,7 @@ class AppIndicatorTray extends GtkTypeSystemTray {
public public
AppIndicatorTray() { AppIndicatorTray() {
if (SystemTray.FORCE_TRAY_TYPE == SystemTray.TYPE_GTKSTATUSICON) { if (SystemTray.FORCE_TRAY_TYPE == SystemTray.TYPE_GTK_STATUSICON) {
// if we force GTK type system tray, don't attempt to load AppIndicator libs // if we force GTK type system tray, don't attempt to load AppIndicator libs
throw new IllegalArgumentException("Unable to start AppIndicator if 'SystemTray.FORCE_TRAY_TYPE' is set to GTK"); throw new IllegalArgumentException("Unable to start AppIndicator if 'SystemTray.FORCE_TRAY_TYPE' is set to GTK");
} }

View File

@ -83,7 +83,7 @@ class GtkSystemTray extends GtkTypeSystemTray {
super.waitForStartup(); super.waitForStartup();
ImageUtils.determineIconSize(SystemTray.TYPE_GTKSTATUSICON); ImageUtils.determineIconSize(SystemTray.TYPE_GTK_STATUSICON);
// we have to be able to set our title, otherwise the gnome-shell extension WILL NOT work // we have to be able to set our title, otherwise the gnome-shell extension WILL NOT work
dispatch(new Runnable() { dispatch(new Runnable() {

View File

@ -69,7 +69,7 @@ class GtkTypeSystemTray extends SystemTray {
} }
} }
} else if (SystemTray.isSwtLoaded) { } else if (SystemTray.isSwtLoaded) {
if (SystemTray.FORCE_TRAY_TYPE != SystemTray.TYPE_GTKSTATUSICON) { if (SystemTray.FORCE_TRAY_TYPE != SystemTray.TYPE_GTK_STATUSICON) {
// GTK system tray has threading issues if we block here (because it is likely in the event thread) // GTK system tray has threading issues if we block here (because it is likely in the event thread)
// AppIndicator version doesn't have this problem // AppIndicator version doesn't have this problem
try { try {

View File

@ -51,7 +51,7 @@ class AppIndicator {
// ALSO WHAT VERSION OF GTK to use? appindiactor1 -> GTk2, appindicator3 -> GTK3. // ALSO WHAT VERSION OF GTK to use? appindiactor1 -> GTk2, appindicator3 -> GTK3.
// appindicator3 doesn't support menu icons via GTK2!! // appindicator3 doesn't support menu icons via GTK2!!
if (SystemTray.FORCE_TRAY_TYPE == SystemTray.TYPE_GTKSTATUSICON) { if (SystemTray.FORCE_TRAY_TYPE == SystemTray.TYPE_GTK_STATUSICON) {
// if we force GTK type system tray, don't attempt to load AppIndicator libs // if we force GTK type system tray, don't attempt to load AppIndicator libs
if (LIBRARY_DEBUG) { if (LIBRARY_DEBUG) {
logger.error("Forcing GTK tray, not using appindicator"); logger.error("Forcing GTK tray, not using appindicator");

View File

@ -64,7 +64,7 @@ class ImageUtils {
} else { } else {
// GtkStatusIcon will USUALLY automatically scale the icon // GtkStatusIcon will USUALLY automatically scale the icon
// AppIndicator will NOT scale the icon // AppIndicator will NOT scale the icon
if (trayType == SystemTray.TYPE_SWING || trayType == SystemTray.TYPE_GTKSTATUSICON) { if (trayType == SystemTray.TYPE_SWING || trayType == SystemTray.TYPE_GTK_STATUSICON) {
// swing or GtkStatusIcon on linux/mac? use the default settings // swing or GtkStatusIcon on linux/mac? use the default settings
SIZE = SystemTray.DEFAULT_LINUX_SIZE; SIZE = SystemTray.DEFAULT_LINUX_SIZE;
} else { } else {