Log exception when failed to initialize java.desktop for better user debugging; Use CLI if in headless mode

This commit is contained in:
Karlatemp 2022-04-30 12:49:28 +08:00
parent 4993e59fd0
commit c37576fda7
No known key found for this signature in database
GPG Key ID: C6B606FF23D8FED7

View File

@ -141,6 +141,9 @@ internal object WindowHelperJvm {
}
if (System.getProperty("mirai.no-desktop") != null) return@run PlatformKind.CLI
kotlin.runCatching {
Class.forName("java.awt.GraphicsEnvironment")
if (GraphicsEnvironment.isHeadless()) return@run PlatformKind.CLI
Class.forName("java.awt.Desktop")
Class.forName("java.awt.Toolkit")
Toolkit.getDefaultToolkit()
@ -160,6 +163,9 @@ internal object WindowHelperJvm {
} else {
return@run PlatformKind.CLI
}
}.onFailure { error ->
if (error.javaClass == ClassNotFoundException::class.java && error.cause == null) return@onFailure
logger.warning("Failed to initialize module `java.desktop`", error)
}.getOrElse {
return@run PlatformKind.CLI
}