Skip to main content
Glama
EnvUtils.kt2.05 kB
package maestro.device.util import java.io.IOException import java.nio.file.Path import java.nio.file.Paths import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException object EnvUtils { val OS_NAME: String = System.getProperty("os.name") val OS_ARCH: String = System.getProperty("os.arch") val OS_VERSION: String = System.getProperty("os.version") /** * @return true, if we're executing from Windows Linux shell (WSL) */ fun isWSL(): Boolean { try { val p1 = ProcessBuilder("printenv", "WSL_DISTRO_NAME").start() if (!p1.waitFor(20, TimeUnit.SECONDS)) throw TimeoutException() if (p1.exitValue() == 0 && String(p1.inputStream.readBytes()).trim().isNotEmpty()) { return true } val p2 = ProcessBuilder("printenv", "IS_WSL").start() if (!p2.waitFor(20, TimeUnit.SECONDS)) throw TimeoutException() if (p2.exitValue() == 0 && String(p2.inputStream.readBytes()).trim().isNotEmpty()) { return true } } catch (ignore: Exception) { // ignore } return false } fun isWindows(): Boolean { return OS_NAME.lowercase().startsWith("windows") } /** * Returns major version of Java, e.g. 8, 11, 17, 21. */ fun getJavaVersion(): Int { // Adapted from https://stackoverflow.com/a/2591122/7009800 val version = System.getProperty("java.version") return if (version.startsWith("1.")) { version.substring(2, 3).toInt() } else { val dot = version.indexOf(".") if (dot != -1) version.substring(0, dot).toInt() else 0 } } } internal fun runProcess(program: String, vararg arguments: String): List<String> { val process = ProcessBuilder(program, *arguments).start() return try { process.inputStream.reader().use { it.readLines().map(String::trim) } } catch (ignore: Exception) { emptyList() } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mobile-dev-inc/Maestro'

If you have feedback or need assistance with the MCP directory API, please join our Discord server