public static int getTrayImageSize() { if (TRAY_SIZE == 0) { if (OS.isLinux()) { TRAY_SIZE = GtkTheme.getIndicatorSize(); } else if (OS.isMacOsX()) { // these are the standard icon sizes. From what I can tell, they are Apple defined, and cannot be changed. if (SizeAndScalingUtil.getMacOSScaleFactor() == 2.0D) { TRAY_SIZE = 44; } else { TRAY_SIZE = 22; } } else if (OS.isWindows()) { TRAY_SIZE = User32.User32.GetSystemMetrics(SM_CYSMICON); } else { // reasonable default TRAY_SIZE = 32; } } if (TRAY_SIZE == 0) { // reasonable default TRAY_SIZE = 32; } return TRAY_SIZE; }
private static boolean isSwingTrayLoaded() { String className; if (OS.isWindows()) { className = "sun.awt.windows.WTrayIconPeer"; } else if (OS.isMacOsX()){ className = "sun.lwawt.macosx.CTrayIcon"; } else { className = "sun.awt.X11.XTrayIconPeer"; } try { // this is important to use reflection, because if JavaFX is not being used, calling getToolkit() will initialize it... java.lang.reflect.Method m = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class); m.setAccessible(true); ClassLoader cl = ClassLoader.getSystemClassLoader(); // if we are using swing the classes are already created and we cannot fix that if it's already loaded. return (null != m.invoke(cl, className)) || (null != m.invoke(cl, "java.awt.SystemTray")); } catch (Throwable e) { if (SystemTray.DEBUG) { logger.debug("Error detecting if the Swing SystemTray is loaded, unexpected error.", e); } } return true; }
public ShellProcessBuilder pipeOutputToNull() { if (OS.isWindows()) { // >NUL on windows pipeToNullString = ">NUL"; } else { // we will "pipe" it to /dev/null on *nix pipeToNullString = ">/dev/null 2>&1"; } return this; }
@Override public void remove() { SwingUtil.invokeLater(new Runnable() { @Override public void run() { if (trayIcon != null) { if (tray != null) { tray.remove(trayIcon); } trayIcon = null; } tray = null; } }); super.remove(); if (OS.isLinux() || OS.isUnix()) { // does not need to be called on the dispatch (it does that). Startup happens in the SystemTray (in a special block), // because we MUST startup the system tray BEFORE to access GTK before we create the swing version (to get size info) GtkEventDispatch.shutdownGui(); } } };
if (OS.isWindows()) { if (path.startsWith("/")) { path = path.substring(1);