mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 13:27:22 -04:00
Should be able to recognize Raspberry Pi and not try and load the Discord RPC (which crashes the game)
This commit is contained in:
parent
f554d8c2c4
commit
ffb562c0aa
@ -29,7 +29,8 @@ internal object DesktopLauncher {
|
|||||||
val game = UncivGame("Desktop")
|
val game = UncivGame("Desktop")
|
||||||
|
|
||||||
|
|
||||||
tryActivateDiscord(game)
|
if(!RaspberryPiDetector.isRaspberryPi()) // No discord RPC for Raspberry Pi, see https://github.com/yairm210/Unciv/issues/1624
|
||||||
|
tryActivateDiscord(game)
|
||||||
|
|
||||||
LwjglApplication(game, config)
|
LwjglApplication(game, config)
|
||||||
}
|
}
|
||||||
@ -67,6 +68,7 @@ internal object DesktopLauncher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun tryActivateDiscord(game: UncivGame) {
|
private fun tryActivateDiscord(game: UncivGame) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val handlers = DiscordEventHandlers()
|
val handlers = DiscordEventHandlers()
|
||||||
DiscordRPC.INSTANCE.Discord_Initialize("647066573147996161", handlers, true, null)
|
DiscordRPC.INSTANCE.Discord_Initialize("647066573147996161", handlers, true, null)
|
||||||
|
61
desktop/src/com/unciv/app/desktop/RaspberryPiDetector.kt
Normal file
61
desktop/src/com/unciv/app/desktop/RaspberryPiDetector.kt
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package com.unciv.app.desktop
|
||||||
|
|
||||||
|
import java.io.BufferedReader
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.io.InputStreamReader
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Raspberry PI helper class
|
||||||
|
* https://stackoverflow.com/questions/37053271/the-ideal-way-to-detect-a-raspberry-pi-from-java-jar
|
||||||
|
* @author wf
|
||||||
|
*/
|
||||||
|
object RaspberryPiDetector {
|
||||||
|
var debug = false
|
||||||
|
/**
|
||||||
|
* check if this java vm runs on a raspberry PI
|
||||||
|
*
|
||||||
|
* @return true if this is running on a Raspbian Linux
|
||||||
|
*/
|
||||||
|
fun isRaspberryPi(): Boolean {
|
||||||
|
val osRelease = osRelease()
|
||||||
|
return osRelease != null && osRelease.contains("Raspbian")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* read the first line from the given file
|
||||||
|
*
|
||||||
|
* @param file
|
||||||
|
* @return the first line
|
||||||
|
*/
|
||||||
|
private fun readFirstLine(file: File): String? {
|
||||||
|
var firstLine: String? = null
|
||||||
|
try {
|
||||||
|
if (file.canRead()) {
|
||||||
|
val fis = FileInputStream(file)
|
||||||
|
val bufferedReader = BufferedReader(
|
||||||
|
InputStreamReader(fis))
|
||||||
|
firstLine = bufferedReader.readLine()
|
||||||
|
fis.close()
|
||||||
|
}
|
||||||
|
} catch (th: Throwable) {
|
||||||
|
if (debug) th.printStackTrace()
|
||||||
|
}
|
||||||
|
return firstLine
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the operating System release
|
||||||
|
*
|
||||||
|
* @return the first line from /etc/os-release or null
|
||||||
|
*/
|
||||||
|
private fun osRelease(): String? {
|
||||||
|
val os = System.getProperty("os.name")
|
||||||
|
if (os.startsWith("Linux")) {
|
||||||
|
val osRelease = File("/etc", "os-release")
|
||||||
|
return readFirstLine(osRelease)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user