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!
|
// BLEH. if gnome-shell is running, IT'S REALLY GNOME!
|
||||||
// we must ALWAYS do this check!!
|
// we must ALWAYS do this check!!
|
||||||
boolean isReallyGnome = Extension.isReallyGnome();
|
boolean isReallyGnome = OS.isGnome();
|
||||||
|
|
||||||
if (isReallyGnome) {
|
if (isReallyGnome) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
logger.error("Auto-detected that gnome-shell is running");
|
logger.error("Auto-detected that gnome-shell is running");
|
||||||
@ -472,9 +472,16 @@ class SystemTray {
|
|||||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.GtkStatusIcon);
|
trayType = selectTypeQuietly(useNativeMenus, TrayType.GtkStatusIcon);
|
||||||
}
|
}
|
||||||
else if ("kde".equalsIgnoreCase(XDG)) {
|
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
|
// 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)) {
|
else if ("pantheon".equalsIgnoreCase(XDG)) {
|
||||||
// elementaryOS. It only supports appindicator (not gtkstatusicon)
|
// elementaryOS. It only supports appindicator (not gtkstatusicon)
|
||||||
// http://bazaar.launchpad.net/~wingpanel-devs/wingpanel/trunk/view/head:/sample/SampleIndicator.vala
|
// http://bazaar.launchpad.net/~wingpanel-devs/wingpanel/trunk/view/head:/sample/SampleIndicator.vala
|
||||||
@ -496,60 +503,25 @@ class SystemTray {
|
|||||||
logger.debug("Currently using the '{}' session type", GDM);
|
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 ("gnome".equalsIgnoreCase(GDM)) {
|
||||||
if (fedoraCheckOutput.contains("ID=fedora")) {
|
// are we fedora? If so, what version?
|
||||||
// now, what VERSION of fedora? 23/24 don't have AppIndicator installed, so we have to use GtkStatusIcon
|
// now, what VERSION of fedora? 23/24/25 don't have AppIndicator installed, so we have to use GtkStatusIcon
|
||||||
int fedoraVersion = 0;
|
int fedoraVersion = OS.getFedoraVersion();
|
||||||
|
if (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) {
|
if (DEBUG) {
|
||||||
logger.debug("Running Fedora version: '{}'", fedoraVersion_);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trayType == null) {
|
// set a property so that Image Resize can adjust. It will check the version info to determine scaling value
|
||||||
// set a property so that Image Resize can adjust
|
System.setProperty("SystemTray_IS_FEDORA_GNOME_ADJUST_SIZE", Integer.toString(fedoraVersion));
|
||||||
System.setProperty("SystemTray_IS_FEDORA_ADJUST_SIZE", Integer.toString(fedoraVersion));
|
|
||||||
|
|
||||||
if (fedoraVersion <= 24) {
|
// 23 is gtk, 24/25 is gtk (but also wrong size unless we adjust it)
|
||||||
// 23 is gtk, 24 is gtk (but wrong size unless we adjust it)
|
|
||||||
Extension.install();
|
Extension.install();
|
||||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.GtkStatusIcon);
|
trayType = selectTypeQuietly(useNativeMenus, TrayType.GtkStatusIcon);
|
||||||
} else {
|
} else {
|
||||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.AppIndicator);
|
trayType = selectTypeQuietly(useNativeMenus, TrayType.AppIndicator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.AppIndicator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ("cinnamon".equalsIgnoreCase(GDM)) {
|
else if ("cinnamon".equalsIgnoreCase(GDM)) {
|
||||||
trayType = selectTypeQuietly(useNativeMenus, TrayType.GtkStatusIcon);
|
trayType = selectTypeQuietly(useNativeMenus, TrayType.GtkStatusIcon);
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import dorkbox.systemTray.SystemTray;
|
import dorkbox.systemTray.SystemTray;
|
||||||
import dorkbox.util.IO;
|
import dorkbox.util.IO;
|
||||||
|
import dorkbox.util.OS;
|
||||||
import dorkbox.util.Property;
|
import dorkbox.util.Property;
|
||||||
import dorkbox.util.process.ShellProcessBuilder;
|
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 '&') */
|
/** 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 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
|
public static
|
||||||
List<String> getEnabledExtensions() {
|
List<String> getEnabledExtensions() {
|
||||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196);
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196);
|
||||||
@ -233,7 +184,7 @@ class Extension {
|
|||||||
|
|
||||||
public static
|
public static
|
||||||
void install() {
|
void install() {
|
||||||
if (!isReallyGnome()) {
|
if (!OS.isGnome()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +192,7 @@ class Extension {
|
|||||||
boolean hasSystemTray;
|
boolean hasSystemTray;
|
||||||
|
|
||||||
// should just be 3.14.1 or 3.20 or similar
|
// should just be 3.14.1 or 3.20 or similar
|
||||||
String gnomeVersion = getGnomeVersion();
|
String gnomeVersion = OS.getGnomeVersion();
|
||||||
if (gnomeVersion == null) {
|
if (gnomeVersion == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -397,7 +348,7 @@ class Extension {
|
|||||||
|
|
||||||
public static
|
public static
|
||||||
void unInstall() {
|
void unInstall() {
|
||||||
if (!isReallyGnome()) {
|
if (!OS.isGnome()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,8 +66,8 @@ class ImageUtils {
|
|||||||
|
|
||||||
public static
|
public static
|
||||||
void determineIconSize() {
|
void determineIconSize() {
|
||||||
double trayScalingFactor = 0;
|
int trayScalingFactor = 0;
|
||||||
double menuScalingFactor = 0;
|
int menuScalingFactor = 0;
|
||||||
|
|
||||||
if (SystemTray.AUTO_TRAY_SIZE) {
|
if (SystemTray.AUTO_TRAY_SIZE) {
|
||||||
if (OS.isWindows()) {
|
if (OS.isWindows()) {
|
||||||
@ -188,74 +188,24 @@ class ImageUtils {
|
|||||||
String XDG = System.getenv("XDG_CURRENT_DESKTOP");
|
String XDG = System.getenv("XDG_CURRENT_DESKTOP");
|
||||||
if (XDG == null) {
|
if (XDG == null) {
|
||||||
// Check if plasmashell is running, if it is -- then we are most likely KDE
|
// Check if plasmashell is running, if it is -- then we are most likely KDE
|
||||||
|
double plasmaVersion = OS.getPlasmaVersion();
|
||||||
try {
|
if (plasmaVersion > 0) {
|
||||||
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";
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ("kde".equalsIgnoreCase(XDG)) {
|
if ("kde".equalsIgnoreCase(XDG)) {
|
||||||
try {
|
double plasmaVersion = OS.getPlasmaVersion();
|
||||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196);
|
|
||||||
PrintStream outputStream = new PrintStream(byteArrayOutputStream);
|
|
||||||
|
|
||||||
// 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
|
// 1 = 16
|
||||||
// 2 = 32
|
// 2 = 32
|
||||||
// 4 = 64
|
// 4 = 64
|
||||||
// 8 = 128
|
// 8 = 128
|
||||||
if (value.startsWith("4")) {
|
if (plasmaVersion > 0) {
|
||||||
trayScalingFactor = 2;
|
trayScalingFactor = 2;
|
||||||
} else if (value.startsWith("5")) {
|
// menuScalingFactor = 1.4;
|
||||||
trayScalingFactor = 8; // it is insane how large the icon is
|
} else if (SystemTray.DEBUG) {
|
||||||
} else {
|
SystemTray.logger.error("Cannot check plasmashell version");
|
||||||
// assume very low version of plasmashell, default 32
|
|
||||||
trayScalingFactor = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
if (SystemTray.DEBUG) {
|
|
||||||
SystemTray.logger.error("Cannot check plasmashell version", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// it's likely a Gnome environment
|
// it's likely a Gnome environment
|
||||||
@ -303,14 +253,14 @@ class ImageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fedora 24 has a wonky size for the indicator (NOT default 16px)
|
// fedora 24+ has a different size for the indicator (NOT default 16px)
|
||||||
int fedoraVersion = Integer.parseInt(System.getProperty("SystemTray_IS_FEDORA_ADJUST_SIZE", "0"));
|
int fedoraVersion = Integer.parseInt(System.getProperty("SystemTray_IS_FEDORA_GNOME_ADJUST_SIZE", "0"));
|
||||||
if (trayScalingFactor == 0 && fedoraVersion >= 23) {
|
if (trayScalingFactor == 0 && fedoraVersion >= 23) {
|
||||||
if (SystemTray.DEBUG) {
|
if (SystemTray.DEBUG) {
|
||||||
SystemTray.logger.debug("Adjusting tray/menu scaling for FEDORA " + fedoraVersion);
|
SystemTray.logger.debug("Adjusting tray/menu scaling for FEDORA " + fedoraVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
trayScalingFactor = 2;
|
trayScalingFactor = 2;
|
||||||
menuScalingFactor = 1.5;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (OS.isMacOsX()) {
|
} else if (OS.isMacOsX()) {
|
||||||
@ -358,13 +308,13 @@ class ImageUtils {
|
|||||||
|
|
||||||
// the DEFAULT scale is 16
|
// the DEFAULT scale is 16
|
||||||
if (trayScalingFactor > 1) {
|
if (trayScalingFactor > 1) {
|
||||||
TRAY_SIZE = (int) (SystemTray.DEFAULT_TRAY_SIZE * trayScalingFactor);
|
TRAY_SIZE = SystemTray.DEFAULT_TRAY_SIZE * trayScalingFactor;
|
||||||
} else {
|
} else {
|
||||||
TRAY_SIZE = SystemTray.DEFAULT_TRAY_SIZE;
|
TRAY_SIZE = SystemTray.DEFAULT_TRAY_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menuScalingFactor > 1) {
|
if (menuScalingFactor > 1) {
|
||||||
ENTRY_SIZE = (int) (SystemTray.DEFAULT_MENU_SIZE * menuScalingFactor);
|
ENTRY_SIZE = SystemTray.DEFAULT_MENU_SIZE * menuScalingFactor;
|
||||||
} else {
|
} else {
|
||||||
ENTRY_SIZE = SystemTray.DEFAULT_MENU_SIZE;
|
ENTRY_SIZE = SystemTray.DEFAULT_MENU_SIZE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user