forked from dorkbox/SystemTray
Move other OS info detection methods to OS.java. Fixed Fedora 25 KDE
This commit is contained in:
parent
c48759725e
commit
ec124384e7
@ -440,10 +440,10 @@ class SystemTray {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// BLEH. if gnome-shell is running, IT'S REALLY GNOME!
|
||||
// we must ALWAYS do this check!!
|
||||
boolean isReallyGnome = Extension.isReallyGnome();
|
||||
boolean isReallyGnome = OS.isGnome();
|
||||
|
||||
if (isReallyGnome) {
|
||||
if (DEBUG) {
|
||||
logger.error("Auto-detected that gnome-shell is running");
|
||||
@ -472,8 +472,15 @@ class SystemTray {
|
||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.GtkStatusIcon);
|
||||
}
|
||||
else if ("kde".equalsIgnoreCase(XDG)) {
|
||||
if (OS.getFedoraVersion() > 0) {
|
||||
// Fedora KDE requires GtkStatusIcon
|
||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.GtkStatusIcon);
|
||||
} else {
|
||||
// kde (at least, plasma 5.5.6) requires appindicator
|
||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.AppIndicator);
|
||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.AppIndicator);
|
||||
}
|
||||
|
||||
// kde 5.8+ is "high DPI", so we need to adjust the scale. Image resize will do that
|
||||
}
|
||||
else if ("pantheon".equalsIgnoreCase(XDG)) {
|
||||
// elementaryOS. It only supports appindicator (not gtkstatusicon)
|
||||
@ -496,56 +503,21 @@ class SystemTray {
|
||||
logger.debug("Currently using the '{}' session type", GDM);
|
||||
}
|
||||
|
||||
// are we fedora? If so, what version?
|
||||
String fedoraCheckOutput = "";
|
||||
try {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196);
|
||||
PrintStream outputStream = new PrintStream(byteArrayOutputStream);
|
||||
|
||||
// cat /etc/os-release
|
||||
final ShellProcessBuilder shell = new ShellProcessBuilder(outputStream);
|
||||
shell.setExecutable("cat");
|
||||
shell.addArgument("/etc/os-release");
|
||||
shell.start();
|
||||
|
||||
fedoraCheckOutput = ShellProcessBuilder.getOutput(byteArrayOutputStream);
|
||||
} catch (Throwable e) {
|
||||
if (DEBUG) {
|
||||
logger.error("Cannot check what version of Fedora is running", e);
|
||||
}
|
||||
}
|
||||
|
||||
if ("gnome".equalsIgnoreCase(GDM)) {
|
||||
if (fedoraCheckOutput.contains("ID=fedora")) {
|
||||
// now, what VERSION of fedora? 23/24 don't have AppIndicator installed, so we have to use GtkStatusIcon
|
||||
int fedoraVersion = 0;
|
||||
|
||||
try {
|
||||
// should be: VERSION_ID=23\n or something
|
||||
int beginIndex = fedoraCheckOutput.indexOf("VERSION_ID=") + 11;
|
||||
String fedoraVersion_ = fedoraCheckOutput.substring(beginIndex, fedoraCheckOutput.indexOf(OS.LINE_SEPARATOR_UNIX, beginIndex));
|
||||
fedoraVersion = Integer.parseInt(fedoraVersion_);
|
||||
|
||||
if (DEBUG) {
|
||||
logger.debug("Running Fedora version: '{}'", fedoraVersion_);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error("Cannot detect what version of Fedora is running. Falling back to GtkStatusIcon", e);
|
||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.GtkStatusIcon);
|
||||
// are we fedora? If so, what version?
|
||||
// now, what VERSION of fedora? 23/24/25 don't have AppIndicator installed, so we have to use GtkStatusIcon
|
||||
int fedoraVersion = OS.getFedoraVersion();
|
||||
if (fedoraVersion > 0) {
|
||||
if (DEBUG) {
|
||||
logger.debug("Running Fedora version: '{}'", fedoraVersion);
|
||||
}
|
||||
|
||||
if (trayType == null) {
|
||||
// set a property so that Image Resize can adjust
|
||||
System.setProperty("SystemTray_IS_FEDORA_ADJUST_SIZE", Integer.toString(fedoraVersion));
|
||||
// set a property so that Image Resize can adjust. It will check the version info to determine scaling value
|
||||
System.setProperty("SystemTray_IS_FEDORA_GNOME_ADJUST_SIZE", Integer.toString(fedoraVersion));
|
||||
|
||||
if (fedoraVersion <= 24) {
|
||||
// 23 is gtk, 24 is gtk (but wrong size unless we adjust it)
|
||||
Extension.install();
|
||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.GtkStatusIcon);
|
||||
} else {
|
||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.AppIndicator);
|
||||
}
|
||||
}
|
||||
// 23 is gtk, 24/25 is gtk (but also wrong size unless we adjust it)
|
||||
Extension.install();
|
||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.GtkStatusIcon);
|
||||
} else {
|
||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.AppIndicator);
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import java.util.List;
|
||||
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.util.IO;
|
||||
import dorkbox.util.OS;
|
||||
import dorkbox.util.Property;
|
||||
import dorkbox.util.process.ShellProcessBuilder;
|
||||
|
||||
@ -50,56 +51,6 @@ class Extension {
|
||||
/** Command to restart the gnome-shell. It is recommended to start it in the background (hence '&') */
|
||||
public static String SHELL_RESTART_COMMAND = "gnome-shell --replace &";
|
||||
|
||||
|
||||
public static
|
||||
boolean isReallyGnome() {
|
||||
try {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196);
|
||||
PrintStream outputStream = new PrintStream(byteArrayOutputStream);
|
||||
|
||||
// ps a | grep [g]nome-shell
|
||||
final ShellProcessBuilder shell = new ShellProcessBuilder(outputStream);
|
||||
shell.setExecutable("ps");
|
||||
shell.addArgument("a");
|
||||
shell.start();
|
||||
|
||||
String output = ShellProcessBuilder.getOutput(byteArrayOutputStream);
|
||||
return output.contains("gnome-shell");
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static
|
||||
String getGnomeVersion() {
|
||||
try {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196);
|
||||
PrintStream outputStream = new PrintStream(byteArrayOutputStream);
|
||||
|
||||
// gnome-shell --version
|
||||
final ShellProcessBuilder shellVersion = new ShellProcessBuilder(outputStream);
|
||||
shellVersion.setExecutable("gnome-shell");
|
||||
shellVersion.addArgument("--version");
|
||||
shellVersion.start();
|
||||
|
||||
String versionString = ShellProcessBuilder.getOutput(byteArrayOutputStream);
|
||||
|
||||
if (!versionString.isEmpty()) {
|
||||
// GNOME Shell 3.14.1
|
||||
String version = versionString.replaceAll("[^\\d.]", "");
|
||||
if (version.length() > 0 && version.indexOf('.') > 0) {
|
||||
// should just be 3.14.1 or 3.20 or similar
|
||||
return version;
|
||||
}
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static
|
||||
List<String> getEnabledExtensions() {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196);
|
||||
@ -233,7 +184,7 @@ class Extension {
|
||||
|
||||
public static
|
||||
void install() {
|
||||
if (!isReallyGnome()) {
|
||||
if (!OS.isGnome()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -241,7 +192,7 @@ class Extension {
|
||||
boolean hasSystemTray;
|
||||
|
||||
// should just be 3.14.1 or 3.20 or similar
|
||||
String gnomeVersion = getGnomeVersion();
|
||||
String gnomeVersion = OS.getGnomeVersion();
|
||||
if (gnomeVersion == null) {
|
||||
return;
|
||||
}
|
||||
@ -397,7 +348,7 @@ class Extension {
|
||||
|
||||
public static
|
||||
void unInstall() {
|
||||
if (!isReallyGnome()) {
|
||||
if (!OS.isGnome()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -66,8 +66,8 @@ class ImageUtils {
|
||||
|
||||
public static
|
||||
void determineIconSize() {
|
||||
double trayScalingFactor = 0;
|
||||
double menuScalingFactor = 0;
|
||||
int trayScalingFactor = 0;
|
||||
int menuScalingFactor = 0;
|
||||
|
||||
if (SystemTray.AUTO_TRAY_SIZE) {
|
||||
if (OS.isWindows()) {
|
||||
@ -188,74 +188,24 @@ class ImageUtils {
|
||||
String XDG = System.getenv("XDG_CURRENT_DESKTOP");
|
||||
if (XDG == null) {
|
||||
// Check if plasmashell is running, if it is -- then we are most likely KDE
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196);
|
||||
PrintStream outputStream = new PrintStream(byteArrayOutputStream);
|
||||
|
||||
// ps a | grep [g]nome-shell
|
||||
final ShellProcessBuilder shell = new ShellProcessBuilder(outputStream);
|
||||
shell.setExecutable("ps");
|
||||
shell.addArgument("a");
|
||||
shell.start();
|
||||
|
||||
|
||||
String output = ShellProcessBuilder.getOutput(byteArrayOutputStream);
|
||||
if (output.contains("plasmashell")) {
|
||||
XDG = "kde";
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// assume we are not KDE. Maybe not the best assumption, but if we get here, something is wrong.
|
||||
if (SystemTray.DEBUG) {
|
||||
SystemTray.logger.error("Unable to check if plasmashell is running.", e);
|
||||
}
|
||||
double plasmaVersion = OS.getPlasmaVersion();
|
||||
if (plasmaVersion > 0) {
|
||||
XDG = "kde";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ("kde".equalsIgnoreCase(XDG)) {
|
||||
try {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196);
|
||||
PrintStream outputStream = new PrintStream(byteArrayOutputStream);
|
||||
double plasmaVersion = OS.getPlasmaVersion();
|
||||
|
||||
// plasma-desktop -v
|
||||
// plasmashell --version
|
||||
final ShellProcessBuilder shellVersion = new ShellProcessBuilder(outputStream);
|
||||
shellVersion.setExecutable("plasmashell");
|
||||
shellVersion.addArgument("--version");
|
||||
shellVersion.start();
|
||||
|
||||
String output = ShellProcessBuilder.getOutput(byteArrayOutputStream);
|
||||
|
||||
if (!output.isEmpty()) {
|
||||
if (SystemTray.DEBUG) {
|
||||
SystemTray.logger.debug("Checking plasma KDE environment, should start with 'plasmashell', value: '{}'", output);
|
||||
}
|
||||
|
||||
// DEFAULT icon size is 16. KDE is bananas on what they did with tray icon scale
|
||||
// should be: plasmashell 5.6.5 or something
|
||||
String s = "plasmashell ";
|
||||
if (output.contains(s)) {
|
||||
String value = output.substring(output.indexOf(s) + s.length(), output.length());
|
||||
|
||||
// 1 = 16
|
||||
// 2 = 32
|
||||
// 4 = 64
|
||||
// 8 = 128
|
||||
if (value.startsWith("4")) {
|
||||
trayScalingFactor = 2;
|
||||
} else if (value.startsWith("5")) {
|
||||
trayScalingFactor = 8; // it is insane how large the icon is
|
||||
} else {
|
||||
// assume very low version of plasmashell, default 32
|
||||
trayScalingFactor = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
if (SystemTray.DEBUG) {
|
||||
SystemTray.logger.error("Cannot check plasmashell version", e);
|
||||
}
|
||||
// 1 = 16
|
||||
// 2 = 32
|
||||
// 4 = 64
|
||||
// 8 = 128
|
||||
if (plasmaVersion > 0) {
|
||||
trayScalingFactor = 2;
|
||||
// menuScalingFactor = 1.4;
|
||||
} else if (SystemTray.DEBUG) {
|
||||
SystemTray.logger.error("Cannot check plasmashell version");
|
||||
}
|
||||
} else {
|
||||
// it's likely a Gnome environment
|
||||
@ -303,14 +253,14 @@ class ImageUtils {
|
||||
}
|
||||
}
|
||||
|
||||
// fedora 24 has a wonky size for the indicator (NOT default 16px)
|
||||
int fedoraVersion = Integer.parseInt(System.getProperty("SystemTray_IS_FEDORA_ADJUST_SIZE", "0"));
|
||||
// fedora 24+ has a different size for the indicator (NOT default 16px)
|
||||
int fedoraVersion = Integer.parseInt(System.getProperty("SystemTray_IS_FEDORA_GNOME_ADJUST_SIZE", "0"));
|
||||
if (trayScalingFactor == 0 && fedoraVersion >= 23) {
|
||||
if (SystemTray.DEBUG) {
|
||||
SystemTray.logger.debug("Adjusting tray/menu scaling for FEDORA " + fedoraVersion);
|
||||
}
|
||||
|
||||
trayScalingFactor = 2;
|
||||
menuScalingFactor = 1.5;
|
||||
}
|
||||
}
|
||||
} else if (OS.isMacOsX()) {
|
||||
@ -358,13 +308,13 @@ class ImageUtils {
|
||||
|
||||
// the DEFAULT scale is 16
|
||||
if (trayScalingFactor > 1) {
|
||||
TRAY_SIZE = (int) (SystemTray.DEFAULT_TRAY_SIZE * trayScalingFactor);
|
||||
TRAY_SIZE = SystemTray.DEFAULT_TRAY_SIZE * trayScalingFactor;
|
||||
} else {
|
||||
TRAY_SIZE = SystemTray.DEFAULT_TRAY_SIZE;
|
||||
}
|
||||
|
||||
if (menuScalingFactor > 1) {
|
||||
ENTRY_SIZE = (int) (SystemTray.DEFAULT_MENU_SIZE * menuScalingFactor);
|
||||
ENTRY_SIZE = SystemTray.DEFAULT_MENU_SIZE * menuScalingFactor;
|
||||
} else {
|
||||
ENTRY_SIZE = SystemTray.DEFAULT_MENU_SIZE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user