Updated documentation, uncommented code form debugging

This commit is contained in:
nathan 2015-11-09 19:55:46 +01:00
parent 8713f77c46
commit 2b6421a45b

View File

@ -16,15 +16,25 @@
package dorkbox.util.tray; package dorkbox.util.tray;
import dorkbox.util.OS; import dorkbox.util.OS;
import dorkbox.util.jna.linux.AppIndicator;
import dorkbox.util.jna.linux.GtkSupport;
import dorkbox.util.process.ShellProcessBuilder;
import dorkbox.util.tray.linux.AppIndicatorTray;
import dorkbox.util.tray.linux.GnomeShellExtension;
import dorkbox.util.tray.linux.GtkSystemTray;
import dorkbox.util.tray.swing.SwingSystemTray; import dorkbox.util.tray.swing.SwingSystemTray;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.URL; import java.net.URL;
@ -73,148 +83,148 @@ class SystemTray {
} }
if (OS.isLinux()) { if (OS.isLinux()) {
// if (GtkSupport.isSupported) { if (GtkSupport.isSupported) {
// // 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
//
// // 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 ignored) {
// } }
// } }
// else if ("XFCE".equalsIgnoreCase(XDG)) { else if ("XFCE".equalsIgnoreCase(XDG)) {
// // NOTE: XFCE uses a OLD version of appindicators, which DO NOT support images in the menu. // XFCE uses a OLD version of appindicators, which DO NOT support images in the menu.
// try { try {
// trayType = GtkSystemTray.class; trayType = GtkSystemTray.class;
// } catch (Throwable ignored) { } catch (Throwable ignored) {
// } }
// } }
// else if ("LXDE".equalsIgnoreCase(XDG)) { else if ("LXDE".equalsIgnoreCase(XDG)) {
// try { try {
// trayType = GtkSystemTray.class; trayType = GtkSystemTray.class;
// } catch (Throwable ignored) { } catch (Throwable ignored) {
// } }
// } }
// else if ("GNOME".equalsIgnoreCase(XDG)) { else if ("GNOME".equalsIgnoreCase(XDG)) {
// // check other DE // check other DE
// String GDM = System.getenv("GDMSESSION"); String GDM = System.getenv("GDMSESSION");
//
// if ("cinnamon".equalsIgnoreCase(GDM)) { if ("cinnamon".equalsIgnoreCase(GDM)) {
// try { try {
// trayType = GtkSystemTray.class; trayType = GtkSystemTray.class;
// } catch (Throwable ignored) { } catch (Throwable ignored) {
// } }
// } }
// 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 ignored) {
// } }
// } }
// 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 ignored) {
// } }
// } }
//
//
// // unknown exactly, install extension and go from there // unknown exactly, 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)
//
// try { try {
// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196);
// PrintStream outputStream = new PrintStream(byteArrayOutputStream); PrintStream outputStream = new PrintStream(byteArrayOutputStream);
//
// // gnome-shell --version // gnome-shell --version
// final ShellProcessBuilder shellVersion = new ShellProcessBuilder(outputStream); final ShellProcessBuilder shellVersion = new ShellProcessBuilder(outputStream);
// shellVersion.setExecutable("gnome-shell"); shellVersion.setExecutable("gnome-shell");
// shellVersion.addArgument("--version"); shellVersion.addArgument("--version");
// shellVersion.start(); shellVersion.start();
//
// String output = ShellProcessBuilder.getOutput(byteArrayOutputStream); String output = ShellProcessBuilder.getOutput(byteArrayOutputStream);
//
// if (!output.isEmpty()) { if (!output.isEmpty()) {
// GnomeShellExtension.install(logger, output); GnomeShellExtension.install(logger, output);
// trayType = GtkSystemTray.class; trayType = GtkSystemTray.class;
// } }
// } catch (Throwable ignored) { } catch (Throwable ignored) {
// trayType = null; trayType = null;
// } }
// } }
// } }
//
// // Try to autodetect if we can use app indicators (or if we need to fallback to GTK indicators) // Try to autodetect if we can use app indicators (or if we need to fallback to GTK indicators)
// if (trayType == null) { if (trayType == null) {
// BufferedReader bin = null; BufferedReader bin = null;
// try { try {
// // the ONLY guaranteed way to determine if indicator-application-service is running (and thus, using app-indicator), // the ONLY guaranteed way to determine if indicator-application-service is running (and thus, using app-indicator),
// // is to look through all /proc/<pid>/status, and first line should be Name:\tindicator-appli // is to look through all /proc/<pid>/status, and first line should be Name:\tindicator-appli
// File proc = new File("/proc"); File proc = new File("/proc");
// File[] listFiles = proc.listFiles(); File[] listFiles = proc.listFiles();
// if (listFiles != null) { if (listFiles != null) {
// for (File procs : listFiles) { for (File procs : listFiles) {
// String name = procs.getName(); String name = procs.getName();
//
// if (!Character.isDigit(name.charAt(0))) { if (!Character.isDigit(name.charAt(0))) {
// continue; continue;
// } }
//
// File status = new File(procs, "status"); File status = new File(procs, "status");
// if (!status.canRead()) { if (!status.canRead()) {
// continue; continue;
// } }
//
// try { try {
// bin = new BufferedReader(new FileReader(status)); bin = new BufferedReader(new FileReader(status));
// String readLine = bin.readLine(); String readLine = bin.readLine();
//
// if (readLine != null && readLine.contains("indicator-app")) { if (readLine != null && readLine.contains("indicator-app")) {
// // make sure we can also load the library (it might be the wrong version) // make sure we can also load the library (it might be the wrong version)
// try { try {
// //noinspection unused //noinspection unused
// final AppIndicator instance = AppIndicator.INSTANCE; final AppIndicator instance = AppIndicator.INSTANCE;
// 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(); e.printStackTrace();
// } }
// break; break;
// } }
// } finally { } finally {
// if (bin != null) { if (bin != null) {
// bin.close(); bin.close();
// bin = null; bin = null;
// } }
// } }
// } }
// } }
// } catch (Throwable ignored) { } catch (Throwable ignored) {
// } finally { } finally {
// if (bin != null) { if (bin != null) {
// try { try {
// bin.close(); bin.close();
// } catch (IOException ignored) { } catch (IOException ignored) {
// } }
// } }
// } }
// } }
//
//
// // fallback... // fallback...
// if (trayType == null) { if (trayType == null) {
// trayType = GtkSystemTray.class; trayType = GtkSystemTray.class;
// } }
//
// if (trayType == null) { if (trayType == null) {
// logger.error("Unable to load the system tray native library. Please write an issue and include your OS type and " + logger.error("Unable to load the system tray native library. Please write an issue and include your OS type and " +
// "configuration"); "configuration");
// } }
// } }
} }
// this is windows OR mac // this is windows OR mac