Fixed logic for checking if gnome

This commit is contained in:
nathan 2016-12-29 23:44:58 +01:00
parent 1ecc8f4605
commit e08b35caa8

View File

@ -283,19 +283,32 @@ class OSUtil {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8196);
PrintStream outputStream = new PrintStream(byteArrayOutputStream);
// ps a | grep gnome-shell
// note: some versions of linux can ONLY access "ps a"; FreeBSD and most linux is "ps x"
// we try "x" first
// ps x | grep gnome-shell
final ShellProcessBuilder shell = new ShellProcessBuilder(outputStream);
ShellProcessBuilder shell = new ShellProcessBuilder(outputStream);
shell.setExecutable("ps");
if (OS.isLinux()) {
shell.addArgument("a");
} else {
shell.addArgument("x");
}
shell.addArgument("x");
shell.start();
String output = ShellProcessBuilder.getOutput(byteArrayOutputStream);
return output.contains("gnome-shell");
boolean contains = output.contains("gnome-shell");
if (!contains && OS.isLinux()) {
// only try again if we are linux
// ps a | grep gnome-shell
shell = new ShellProcessBuilder(outputStream);
shell.setExecutable("ps");
shell.addArgument("a");
shell.start();
output = ShellProcessBuilder.getOutput(byteArrayOutputStream);
contains = output.contains("gnome-shell");
}
return contains;
} catch (Throwable ignored) {
}