Compare commits
13 Commits
Version_1.
...
master
Author | SHA1 | Date |
---|---|---|
Robinson | b2926a4693 | |
Robinson | 0598176fe0 | |
Robinson | b9f921bf06 | |
Robinson | cd2d50d5d8 | |
Robinson | e0b4eded81 | |
Robinson | 0c1f718f49 | |
Robinson | 4b90e718ca | |
Robinson | da300e87dc | |
Nohus | 111d48db7c | |
Nohus | 6a37f3e652 | |
Robinson | 509e4c8e0a | |
Robinson | 614baf966f | |
Robinson | e204a8f781 |
|
@ -20,7 +20,7 @@ Maven Info
|
|||
<dependency>
|
||||
<groupId>com.dorkbox</groupId>
|
||||
<artifactId>OS</artifactId>
|
||||
<version>1.8</version>
|
||||
<version>1.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
@ -30,7 +30,7 @@ Gradle Info
|
|||
```
|
||||
dependencies {
|
||||
...
|
||||
implementation("com.dorkbox:OS:1.8")
|
||||
implementation("com.dorkbox:OS:1.11")
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -24,19 +24,19 @@ gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS // always show th
|
|||
|
||||
|
||||
plugins {
|
||||
id("com.dorkbox.GradleUtils") version "3.17"
|
||||
id("com.dorkbox.GradleUtils") version "3.18"
|
||||
id("com.dorkbox.Licensing") version "2.22"
|
||||
id("com.dorkbox.VersionUpdate") version "2.8"
|
||||
id("com.dorkbox.GradlePublish") version "1.18"
|
||||
id("com.dorkbox.GradlePublish") version "1.22"
|
||||
|
||||
kotlin("jvm") version "1.8.0"
|
||||
kotlin("jvm") version "1.9.0"
|
||||
}
|
||||
|
||||
object Extras {
|
||||
// set for the project
|
||||
const val description = "Information about the system, Java runtime, OS, Window Manager, and Desktop Environment."
|
||||
const val group = "com.dorkbox"
|
||||
const val version = "1.8"
|
||||
const val version = "1.11"
|
||||
|
||||
// set as project.ext
|
||||
const val name = "OS"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
@ -27,7 +27,7 @@ object OS {
|
|||
/**
|
||||
* Gets the version number.
|
||||
*/
|
||||
const val version = "1.8"
|
||||
const val version = "1.11"
|
||||
|
||||
init {
|
||||
// Add this project to the updates system, which verifies this class + UUID + version information
|
||||
|
@ -438,12 +438,13 @@ object OS {
|
|||
* This is based on an aggregate of the answers provided here: [https://stackoverflow.com/questions/35421699/how-to-invoke-external-command-from-within-kotlin-code]
|
||||
*/
|
||||
private fun execute(vararg args: String, timeout: Long = 60): String {
|
||||
return ProcessBuilder(args.toList())
|
||||
val process = ProcessBuilder(args.toList())
|
||||
.redirectOutput(ProcessBuilder.Redirect.PIPE)
|
||||
.redirectError(ProcessBuilder.Redirect.PIPE)
|
||||
.start()
|
||||
.apply { waitFor(timeout, TimeUnit.SECONDS) }
|
||||
.inputStream.bufferedReader().readText().trim()
|
||||
val text = process.inputStream.bufferedReader().readText().trim()
|
||||
process.waitFor(timeout, TimeUnit.SECONDS)
|
||||
return text
|
||||
}
|
||||
|
||||
// true if the exit code is 0 (meaning standard exit)
|
||||
|
@ -515,8 +516,17 @@ object OS {
|
|||
try {
|
||||
val output = execute("cmd.exe", "/c", "ver")
|
||||
if (output.isNotEmpty()) {
|
||||
val index = output.indexOf("Version")
|
||||
val versionInfoOnly = output.substring(index + 8, output.indexOf("]"))
|
||||
// OF NOTE: It is possible to have a different encoding of windows, where the word "Version" doesn't exist.
|
||||
// in this case, we'll just take the next set of numbers available
|
||||
// Microsoft Windows [Version 10.0.22000.2600]
|
||||
// Microsoft Windows [??? 10.0.22621.2283] (different encoding)
|
||||
|
||||
// slice out the [] because we don't want to include windows product names! (like Windows 2012) in the name!
|
||||
// I don't specifically have this version to test, however it is easy enough to guard against.
|
||||
val shortenedOutput = output.substring(output.indexOf("[") + 1, output.indexOf("]"))
|
||||
val index = shortenedOutput.indexOfFirst { it.isDigit() }
|
||||
val versionInfoOnly = shortenedOutput.substring(index, shortenedOutput.length)
|
||||
|
||||
val split = versionInfoOnly.split(".").toTypedArray()
|
||||
if (split.size == 4) {
|
||||
version[0] = split[0].toInt()
|
||||
|
@ -824,7 +834,7 @@ object OS {
|
|||
if (data == null) {
|
||||
// reading the file didn't work for whatever reason...
|
||||
// uname -v
|
||||
data = execute("uname", "-v").contains("-Microsoft")
|
||||
data = execute("/usr/bin/uname", "-v").contains("-Microsoft")
|
||||
}
|
||||
|
||||
if (data == true) {
|
||||
|
@ -845,7 +855,7 @@ object OS {
|
|||
// running as root (also can be "sudo" user). A lot slower that checking a sys env, but this is guaranteed to work
|
||||
try {
|
||||
// id -u
|
||||
isSudoOrRoot = "0" == execute("id", "-u")
|
||||
isSudoOrRoot = "0" == execute("/usr/bin/id", "-u")
|
||||
} catch (ignored: Throwable) {
|
||||
}
|
||||
}
|
||||
|
@ -885,7 +895,7 @@ object OS {
|
|||
// dpkg-query: package 'libappindicator3' is not installed
|
||||
val is_dpkg = File("/usr/bin/dpkg").canExecute()
|
||||
if (is_dpkg) {
|
||||
return !execute("dpkg", "-L", packageName).contains("is not installed")
|
||||
return !execute("/usr/bin/dpkg", "-L", packageName).contains("is not installed")
|
||||
}
|
||||
|
||||
// rpm
|
||||
|
@ -893,7 +903,7 @@ object OS {
|
|||
// package libappindicator234 is not installed
|
||||
val is_rpm = File("/usr/bin/rpm").canExecute()
|
||||
if (is_rpm) {
|
||||
return !execute("rpm", "-q", packageName).contains("is not installed")
|
||||
return !execute("/usr/bin/rpm", "-q", packageName).contains("is not installed")
|
||||
}
|
||||
|
||||
|
||||
|
@ -904,7 +914,7 @@ object OS {
|
|||
try {
|
||||
// use the exit code to determine if the packages exists on the system
|
||||
// 0 the package exists, 1 it doesn't
|
||||
return executeStatus("pacman", "-Qi", packageName)
|
||||
return executeStatus("/usr/bin/pacman", "-Qi", packageName)
|
||||
|
||||
//return start == 0
|
||||
} catch (ignored: Exception) {
|
||||
|
@ -971,12 +981,12 @@ object OS {
|
|||
// we try "x" first
|
||||
|
||||
// ps x | grep gnome-shell
|
||||
var contains = execute("ps", "x").contains("gnome-shell")
|
||||
var contains = execute("/usr/bin/ps", "x").contains("gnome-shell")
|
||||
if (!contains && isLinux) {
|
||||
// only try again if we are linux
|
||||
|
||||
// ps a | grep gnome-shell
|
||||
contains = execute("ps", "a").contains("gnome-shell")
|
||||
contains = execute("/usr/bin/ps", "a").contains("gnome-shell")
|
||||
}
|
||||
contains
|
||||
} catch (ignored: Throwable) {
|
||||
|
@ -994,7 +1004,7 @@ object OS {
|
|||
} else {
|
||||
try {
|
||||
// gnome-shell --version
|
||||
val versionString = execute("gnome-shell", "--version")
|
||||
val versionString = execute("/usr/bin/gnome-shell", "--version")
|
||||
if (versionString.isNotEmpty()) {
|
||||
// GNOME Shell 3.14.1
|
||||
val version = versionString.replace("[^\\d.]".toRegex(), "")
|
||||
|
@ -1018,8 +1028,7 @@ object OS {
|
|||
val XDG = getEnv("XDG_CURRENT_DESKTOP")
|
||||
if (XDG == null) {
|
||||
// Check if plasmashell is running, if it is -- then we are most likely KDE
|
||||
val plasmaVersion = plasmaVersion
|
||||
plasmaVersion > 0
|
||||
plasmaVersionFull != null && !plasmaVersionFull!!.startsWith("0")
|
||||
} else {
|
||||
"kde".equals(XDG, ignoreCase = true)
|
||||
}
|
||||
|
@ -1037,7 +1046,7 @@ object OS {
|
|||
try {
|
||||
// plasma-desktop -v
|
||||
// plasmashell --version
|
||||
val output = execute("plasmashell", "--version")
|
||||
val output = execute("/usr/bin/plasmashell", "--version")
|
||||
if (output.isNotEmpty()) {
|
||||
// DEFAULT icon size is 16. KDE is bananas on what they did with tray icon scale
|
||||
// should be: plasmashell 5.6.5 or something
|
||||
|
@ -1056,25 +1065,6 @@ object OS {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The first two decimal places of the version number of plasma shell (if running) as a double.
|
||||
*
|
||||
* @return cannot represent '5.6.5' as a number, so we return just the first two decimal places instead
|
||||
*/
|
||||
val plasmaVersion: Double by lazy {
|
||||
if (plasmaVersionFull == null || plasmaVersionFull!!.startsWith("0")) {
|
||||
0.0
|
||||
} else {
|
||||
// this isn't the BEST way to do this, but it's simple and easy to understand
|
||||
val split = plasmaVersionFull!!.split(".", limit = 3).toTypedArray()
|
||||
if (split.size > 2) {
|
||||
(split[0] + "." + split[1]).toDouble()
|
||||
} else {
|
||||
split[0].toDouble()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val isXfce: Boolean by lazy {
|
||||
if (!isLinux && !isUnix) {
|
||||
false
|
||||
|
@ -1084,12 +1074,12 @@ object OS {
|
|||
// we try "x" first
|
||||
|
||||
// ps x | grep xfce
|
||||
var contains = execute("ps", "x").contains("xfce")
|
||||
var contains = execute("/usr/bin/ps", "x").contains("xfce")
|
||||
if (!contains && isLinux) {
|
||||
// only try again if we are linux
|
||||
|
||||
// ps a | grep gnome-shell
|
||||
contains = execute("ps", "a").contains("xfce")
|
||||
contains = execute("/usr/bin/ps", "a").contains("xfce")
|
||||
}
|
||||
contains
|
||||
} catch (ignored: Throwable) {
|
||||
|
@ -1110,7 +1100,7 @@ object OS {
|
|||
} else {
|
||||
try {
|
||||
// nautilus --version
|
||||
val output = execute("nautilus", "--version")
|
||||
val output = execute("/usr/bin/nautilus", "--version")
|
||||
if (output.isNotEmpty()) {
|
||||
// should be: GNOME nautilus 3.14.3 or something
|
||||
val s = "GNOME nautilus "
|
||||
|
@ -1130,7 +1120,7 @@ object OS {
|
|||
} else {
|
||||
try {
|
||||
// ps aux | grep chromeos
|
||||
execute("ps", "aux").contains("chromeos")
|
||||
execute("/usr/bin/ps", "aux").contains("chromeos")
|
||||
} catch (ignored: Throwable) {
|
||||
false
|
||||
}
|
||||
|
@ -1150,7 +1140,7 @@ object OS {
|
|||
try {
|
||||
// xfconf-query -c xfce4-panel -l
|
||||
val commands: MutableList<String> = ArrayList()
|
||||
commands.add("xfconf-query")
|
||||
commands.add("/usr/bin/xfconf-query")
|
||||
commands.add("-c")
|
||||
commands.add(channel)
|
||||
if (property != null) {
|
||||
|
|
Loading…
Reference in New Issue