Fix screen rotation crashing

This commit is contained in:
Butterscotch! committed 2023-06-13 20:30:43 -04:00
1 parent a489e32828
commit 81b7ea0967
4 files changed
+58 -126

No files matched your search

+1 -1
View File
@@ -146,7 +146,7 @@ android {
targetSdk = 33
// Defines the version number of your app.
versionCode = 5
versionCode = 6
// Defines a user-friendly version name for your app.
versionName = "0.7.0"
+2 -1
View File
@@ -17,7 +17,8 @@
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:exported="true">
android:exported="true"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
+38 -85
View File
@@ -3,99 +3,52 @@
package dev.slimevr
import io.eiren.util.logging.LogManager
import org.apache.commons.cli.CommandLine
import org.apache.commons.cli.CommandLineParser
import org.apache.commons.cli.DefaultParser
import org.apache.commons.cli.HelpFormatter
import org.apache.commons.cli.Options
import org.apache.commons.lang3.SystemUtils
import io.ktor.server.engine.embeddedServer
import io.ktor.server.http.content.defaultResource
import io.ktor.server.http.content.resources
import io.ktor.server.http.content.static
import io.ktor.server.http.content.staticBasePackage
import io.ktor.server.netty.Netty
import io.ktor.server.routing.routing
import java.io.File
import java.io.IOException
import java.lang.System
import java.net.ServerSocket
import kotlin.concurrent.thread
import kotlin.system.exitProcess
val VERSION = "v0.7.0/android"
lateinit var vrServer: VRServer
private set
val vrServerInitialized: Boolean
get() = ::vrServer.isInitialized
fun main(args: Array<String>) {
System.setProperty("awt.useSystemAAFontSettings", "on")
System.setProperty("swing.aatext", "true")
val parser: CommandLineParser = DefaultParser()
val formatter = HelpFormatter()
val options = Options()
options.addOption("h", "help", false, "Show help")
options.addOption("V", "version", false, "Show version")
val cmd: CommandLine = try {
parser.parse(options, args, true)
} catch (e: org.apache.commons.cli.ParseException) {
formatter.printHelp("slimevr.jar", options)
exitProcess(1)
}
if (cmd.hasOption("help")) {
formatter.printHelp("slimevr.jar", options)
exitProcess(0)
}
if (cmd.hasOption("version")) {
println("SlimeVR Server $VERSION")
exitProcess(0)
}
if (cmd.args.isEmpty()) {
System.err.println("No command specified, expected 'run'")
exitProcess(1)
}
if (!cmd.args[0].equals("run", true)) {
System.err.println("Unknown command: ${cmd.args[0]}, expected 'run'")
exitProcess(1)
}
val dir = File("").absoluteFile
try {
LogManager.initialize(dir)
} catch (e1: java.lang.Exception) {
e1.printStackTrace()
}
LogManager.info("Running version $VERSION")
if (!SystemUtils.isJavaVersionAtLeast(org.apache.commons.lang3.JavaVersion.JAVA_17)) {
LogManager.severe("SlimeVR start-up error! A minimum of Java 17 is required.")
return
}
try {
// This is disabled because the config can't be read at this point
// new ServerSocket(6969).close();
ServerSocket(35903).close()
ServerSocket(21110).close()
} catch (e: IOException) {
LogManager
.severe(
"SlimeVR start-up error! Required ports are busy. " +
"Make sure there is no other instance of SlimeVR Server running."
)
LogManager.closeLogger()
return
}
try {
vrServer = VRServer()
vrServer.start()
Keybinding(vrServer)
val scanner = thread {
while (true) {
if (readln() == "exit") {
vrServer.interrupt()
break
}
fun main(mainActivity: MainActivity) {
// Host the web GUI server
embeddedServer(Netty, port = 8080) {
routing {
static("/") {
staticBasePackage = "web-gui"
resources()
defaultResource("index.html")
}
}
vrServer.join()
scanner.join()
LogManager.closeLogger()
exitProcess(0)
} catch (e: Throwable) {
e.printStackTrace()
exitProcess(1)
}.start(wait = false)
thread(start = true, name = "Main VRServer Thread") {
try {
LogManager.initialize(mainActivity.filesDir)
} catch (e1: java.lang.Exception) {
e1.printStackTrace()
}
LogManager.info("Running version $VERSION")
try {
vrServer = VRServer(File(mainActivity.filesDir, "vrconfig.yml").absolutePath)
vrServer.start()
Keybinding(vrServer)
vrServer.join()
LogManager.closeLogger()
exitProcess(0)
} catch (e: Throwable) {
e.printStackTrace()
exitProcess(1)
}
}
}
@@ -4,56 +4,34 @@ import android.os.Bundle
import android.webkit.WebView
import androidx.appcompat.app.AppCompatActivity
import io.eiren.util.logging.LogManager
import io.ktor.server.engine.embeddedServer
import io.ktor.server.http.content.*
import io.ktor.server.netty.Netty
import io.ktor.server.routing.routing
import java.io.File
import kotlin.concurrent.thread
import kotlin.system.exitProcess
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Host the web GUI server
embeddedServer(Netty, port = 8080) {
routing {
static("/") {
staticBasePackage = "web-gui"
resources()
defaultResource("index.html")
}
}
}.start(wait = false)
// Initialize logger (doesn't re-initialize if already run)
try {
LogManager.initialize(filesDir)
} catch (e1: java.lang.Exception) {
e1.printStackTrace()
}
// Start the server if it isn't already running
if (!vrServerInitialized) {
LogManager.info("[MainActivity] VRServer isn't running yet, starting it...")
main(this)
} else {
LogManager.info("[MainActivity] VRServer is already running, skipping initialization.")
}
// Load the web GUI web page
LogManager.info("[MainActivity] Initializing GUI WebView...")
val guiWebView = findViewById<WebView>(R.id.guiWebView)
guiWebView.settings.javaScriptEnabled = true
guiWebView.settings.domStorageEnabled = true
guiWebView.settings.setSupportZoom(true)
guiWebView.loadUrl("http://localhost:8080/")
thread(start = true, name = "Main VRServer Thread") {
try {
LogManager.initialize(filesDir)
} catch (e1: java.lang.Exception) {
e1.printStackTrace()
}
LogManager.info("Running version $VERSION")
try {
vrServer = VRServer(File(filesDir, "vrconfig.yml").absolutePath)
vrServer.start()
Keybinding(vrServer)
vrServer.join()
LogManager.closeLogger()
exitProcess(0)
} catch (e: Throwable) {
e.printStackTrace()
exitProcess(1)
}
}
guiWebView.loadUrl("http://127.0.0.1:8080/")
LogManager.info("[MainActivity] GUI WebView has been initialized and loaded.")
}
}