Cleaned up/cached more OS/DE methods

This commit is contained in:
nathan 2018-10-26 01:05:54 +02:00
parent 1440b4ac37
commit 346fc38cd7

View File

@ -290,7 +290,7 @@ class OSUtil {
return getInfo().contains("ID=" + id +"\n"); return getInfo().contains("ID=" + id +"\n");
} }
private static Boolean isArch = null; private static volatile Boolean isArch = null;
public static public static
boolean isArch() { boolean isArch() {
if (isArch == null) { if (isArch == null) {
@ -299,7 +299,7 @@ class OSUtil {
return isArch; return isArch;
} }
private static Boolean isDebian = null; private static volatile Boolean isDebian = null;
public static public static
boolean isDebian() { boolean isDebian() {
if (isDebian == null) { if (isDebian == null) {
@ -308,7 +308,7 @@ class OSUtil {
return isDebian; return isDebian;
} }
private static Boolean isElementaryOS = null; private static volatile Boolean isElementaryOS = null;
public static public static
boolean isElementaryOS() { boolean isElementaryOS() {
if (isElementaryOS == null) { if (isElementaryOS == null) {
@ -326,7 +326,7 @@ class OSUtil {
return isElementaryOS; return isElementaryOS;
} }
private static Boolean isFedora = null; private static volatile Boolean isFedora = null;
public static public static
boolean isFedora() { boolean isFedora() {
if (isFedora == null) { if (isFedora == null) {
@ -335,7 +335,7 @@ class OSUtil {
return isFedora; return isFedora;
} }
private static Integer fedoraVersion = null; private static volatile Integer fedoraVersion = null;
public static public static
int getFedoraVersion() { int getFedoraVersion() {
if (fedoraVersion != null) { if (fedoraVersion != null) {
@ -366,7 +366,7 @@ class OSUtil {
return fedoraVersion; return fedoraVersion;
} }
private static Boolean isLinuxMint = null; private static volatile Boolean isLinuxMint = null;
public static public static
boolean isLinuxMint() { boolean isLinuxMint() {
if (isLinuxMint == null) { if (isLinuxMint == null) {
@ -375,7 +375,7 @@ class OSUtil {
return isLinuxMint; return isLinuxMint;
} }
private static Boolean isUbuntu = null; private static volatile Boolean isUbuntu = null;
public static public static
boolean isUbuntu() { boolean isUbuntu() {
if (isUbuntu == null) { if (isUbuntu == null) {
@ -384,7 +384,7 @@ class OSUtil {
return isUbuntu; return isUbuntu;
} }
private static int[] ubuntuVersion = null; private static volatile int[] ubuntuVersion = null;
public static public static
int[] getUbuntuVersion() { int[] getUbuntuVersion() {
if (ubuntuVersion != null) { if (ubuntuVersion != null) {
@ -557,15 +557,6 @@ class OSUtil {
return EnvType.Unknown; return EnvType.Unknown;
} }
private static volatile Boolean isGnome = null;
private static volatile Boolean isKDE = null;
private static volatile Boolean isChromeOS = null;
private static volatile Boolean isNautilus = null;
private static volatile String getPlasmaVersionFull = null;
public static public static
boolean isX11() { boolean isX11() {
EnvType env = getType(); EnvType env = getType();
@ -589,6 +580,8 @@ class OSUtil {
return env == OSUtil.DesktopEnv.Env.Unity || env == OSUtil.DesktopEnv.Env.Unity7; return env == OSUtil.DesktopEnv.Env.Unity || env == OSUtil.DesktopEnv.Env.Unity7;
} }
private static volatile Boolean isGnome = null;
public static public static
boolean isGnome() { boolean isGnome() {
if (!OS.isLinux() && !OS.isUnix()) { if (!OS.isLinux() && !OS.isUnix()) {
@ -626,20 +619,31 @@ class OSUtil {
} }
isGnome = contains; isGnome = contains;
return contains; return isGnome;
} catch (Throwable ignored) { } catch (Throwable ignored) {
} }
isGnome = false; isGnome = false;
return false; return isGnome;
} }
private static volatile boolean hasGnomeVersion = false;
private static volatile String gnomeVersion = null;
/**
* @return a string representing the current gnome-shell version, or NULL if it could not be found
*/
public static public static
String getGnomeVersion() { String getGnomeVersion() {
if (!OS.isLinux() && !OS.isUnix()) { if (hasGnomeVersion) {
return ""; return gnomeVersion;
} }
if (!OS.isLinux() && !OS.isUnix()) {
return null;
}
hasGnomeVersion = true;
try { try {
// gnome-shell --version // gnome-shell --version
final ShellExecutor shellVersion = new ShellExecutor(); final ShellExecutor shellVersion = new ShellExecutor();
@ -654,15 +658,18 @@ class OSUtil {
String version = versionString.replaceAll("[^\\d.]", ""); String version = versionString.replaceAll("[^\\d.]", "");
if (version.length() > 0 && version.indexOf('.') > 0) { if (version.length() > 0 && version.indexOf('.') > 0) {
// should just be 3.14.1 or 3.20 or similar // should just be 3.14.1 or 3.20 or similar
return version; gnomeVersion = version;
return gnomeVersion;
} }
} }
} catch (Throwable ignored) { } catch (Throwable ignored) {
} }
return null; gnomeVersion = null;
return gnomeVersion;
} }
private static volatile Boolean isKDE = null;
public static public static
boolean isKDE() { boolean isKDE() {
if (isKDE != null) { if (isKDE != null) {
@ -693,6 +700,11 @@ class OSUtil {
public static public static
double getPlasmaVersion() { double getPlasmaVersion() {
String versionAsString = getPlasmaVersionFull(); String versionAsString = getPlasmaVersionFull();
if (versionAsString == null) {
return 0;
}
if (versionAsString.startsWith("0")) { if (versionAsString.startsWith("0")) {
return 0; return 0;
} }
@ -706,22 +718,26 @@ class OSUtil {
} }
} }
private static volatile boolean hasPlasmaVersion = false;
private static volatile String getPlasmaVersionFull = null;
/** /**
* The full version number of plasma shell (if running) as a String. * The full version number of plasma shell (if running) as a String.
* *
* @return cannot represent '5.6.5' as a number, so we return a String instead * @return cannot represent '5.6.5' as a number, so we return a String instead or NULL if unknown
*/ */
public static public static
String getPlasmaVersionFull() { String getPlasmaVersionFull() {
if (getPlasmaVersionFull != null) { if (hasPlasmaVersion) {
return getPlasmaVersionFull; return getPlasmaVersionFull;
} }
if (!OS.isLinux() && !OS.isUnix()) { if (!OS.isLinux() && !OS.isUnix()) {
getPlasmaVersionFull = ""; return null;
return "";
} }
hasPlasmaVersion = true;
try { try {
// plasma-desktop -v // plasma-desktop -v
// plasmashell --version // plasmashell --version
@ -739,20 +755,20 @@ class OSUtil {
if (isValidCommand(s, output)) { if (isValidCommand(s, output)) {
String substring = output.substring(output.indexOf(s) + s.length(), output.length()); String substring = output.substring(output.indexOf(s) + s.length(), output.length());
getPlasmaVersionFull = substring; getPlasmaVersionFull = substring;
return substring; return getPlasmaVersionFull;
} }
} }
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
getPlasmaVersionFull = "0"; return null;
return "0";
} }
private static volatile Boolean isNautilus = null;
/** /**
* There are sometimes problems with nautilus (the file browser) and some GTK methods. It is rediculous for me to have to * There are sometimes problems with nautilus (the file browser) and some GTK methods. It is ridiculous for me to have to
* work around their bugs like this. * work around their bugs like this.
* <p> * <p>
* see: https://askubuntu.com/questions/788182/nautilus-not-opening-up-showing-glib-error * see: https://askubuntu.com/questions/788182/nautilus-not-opening-up-showing-glib-error
@ -794,6 +810,7 @@ class OSUtil {
} }
private static volatile Boolean isChromeOS = null;
public static public static
boolean isChromeOS() { boolean isChromeOS() {
if (isChromeOS == null) { if (isChromeOS == null) {