mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-04-06 02:01:58 +02:00
Remove Ktor dependency (#1655)
This commit is contained in:
2
server/android/.gitignore
vendored
2
server/android/.gitignore
vendored
@@ -1,3 +1,3 @@
|
||||
/build
|
||||
/src/main/resources/web-gui
|
||||
/src/main/assets/web-gui
|
||||
/secrets
|
||||
|
||||
@@ -29,7 +29,7 @@ java {
|
||||
}
|
||||
|
||||
tasks.register<Copy>("copyGuiAssets") {
|
||||
val target = layout.projectDirectory.dir("src/main/resources/web-gui")
|
||||
val target = layout.projectDirectory.dir("src/main/assets/web-gui")
|
||||
delete(target)
|
||||
from(rootProject.layout.projectDirectory.dir("gui/dist"))
|
||||
into(target)
|
||||
@@ -86,10 +86,6 @@ dependencies {
|
||||
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
|
||||
androidTestImplementation("androidx.test.ext:junit:1.3.0")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.7.0")
|
||||
// For hosting web GUI
|
||||
implementation("io.ktor:ktor-server-core:2.3.13")
|
||||
implementation("io.ktor:ktor-server-netty:2.3.13")
|
||||
implementation("io.ktor:ktor-server-caching-headers:2.3.13")
|
||||
|
||||
// Serial
|
||||
implementation("com.github.mik3y:usb-serial-for-android:3.7.0")
|
||||
|
||||
@@ -12,50 +12,15 @@ import dev.slimevr.android.tracking.trackers.hid.AndroidHIDManager
|
||||
import dev.slimevr.config.ConfigManager
|
||||
import dev.slimevr.tracking.trackers.Tracker
|
||||
import io.eiren.util.logging.LogManager
|
||||
import io.ktor.http.CacheControl
|
||||
import io.ktor.http.CacheControl.Visibility
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.engine.embeddedServer
|
||||
import io.ktor.server.http.content.CachingOptions
|
||||
import io.ktor.server.http.content.staticResources
|
||||
import io.ktor.server.netty.Netty
|
||||
import io.ktor.server.netty.NettyApplicationEngine
|
||||
import io.ktor.server.plugins.cachingheaders.CachingHeaders
|
||||
import io.ktor.server.routing.routing
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.io.File
|
||||
import java.time.ZonedDateTime
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
lateinit var webServer: NettyApplicationEngine
|
||||
private set
|
||||
|
||||
val webServerInitialized: Boolean
|
||||
get() = ::webServer.isInitialized
|
||||
|
||||
var webServerPort = 0
|
||||
|
||||
lateinit var vrServer: VRServer
|
||||
private set
|
||||
val vrServerInitialized: Boolean
|
||||
get() = ::vrServer.isInitialized
|
||||
|
||||
fun startWebServer() {
|
||||
// Host the web GUI server
|
||||
webServer = embeddedServer(Netty, port = 0) {
|
||||
routing {
|
||||
install(CachingHeaders) {
|
||||
options { _, _ ->
|
||||
CachingOptions(CacheControl.NoStore(Visibility.Public), ZonedDateTime.now())
|
||||
}
|
||||
}
|
||||
staticResources("/", "web-gui", "index.html")
|
||||
}
|
||||
}.start(wait = false)
|
||||
webServerPort = runBlocking { webServer.resolvedConnectors().first().port }
|
||||
}
|
||||
|
||||
fun startVRServer(activity: AppCompatActivity) {
|
||||
thread(start = true, name = "Main VRServer Thread") {
|
||||
try {
|
||||
|
||||
@@ -3,10 +3,14 @@ package dev.slimevr.android
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.webkit.JavascriptInterface
|
||||
import android.webkit.WebSettings
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebResourceResponse
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import io.eiren.util.logging.LogManager
|
||||
import java.io.IOException
|
||||
import java.net.URLConnection
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import kotlin.concurrent.withLock
|
||||
|
||||
@@ -28,14 +32,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
initLock.withLock {
|
||||
// Start the GUI if it isn't already running
|
||||
if (!webServerInitialized) {
|
||||
LogManager.info("[MainActivity] WebServer isn't running yet, starting it...")
|
||||
startWebServer()
|
||||
} else {
|
||||
LogManager.info("[MainActivity] WebServer is already running, skipping initialization.")
|
||||
}
|
||||
|
||||
// Start the server if it isn't already running
|
||||
if (!vrServerInitialized) {
|
||||
LogManager.info("[MainActivity] VRServer isn't running yet, starting it...")
|
||||
@@ -53,6 +49,35 @@ class MainActivity : AppCompatActivity() {
|
||||
// Enable debug mode
|
||||
WebView.setWebContentsDebuggingEnabled(true)
|
||||
|
||||
// Handle path resolution
|
||||
guiWebView.webViewClient = object : WebViewClient() {
|
||||
override fun shouldInterceptRequest(
|
||||
view: WebView,
|
||||
request: WebResourceRequest,
|
||||
): WebResourceResponse? {
|
||||
if ((request.url.scheme != "http" && request.url.scheme != "https") ||
|
||||
request.url.host != "slimevr.gui"
|
||||
) {
|
||||
return null
|
||||
}
|
||||
|
||||
val path = when (request.url.path) {
|
||||
null, "", "/" -> "/index.html"
|
||||
else -> request.url.path
|
||||
}
|
||||
|
||||
return try {
|
||||
WebResourceResponse(
|
||||
URLConnection.guessContentTypeFromName(path) ?: "text/plain",
|
||||
null,
|
||||
assets.open("web-gui$path"),
|
||||
)
|
||||
} catch (_: IOException) {
|
||||
WebResourceResponse(null, null, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set required features
|
||||
guiWebView.settings.javaScriptEnabled = true
|
||||
guiWebView.settings.domStorageEnabled = true
|
||||
@@ -66,12 +91,8 @@ class MainActivity : AppCompatActivity() {
|
||||
guiWebView.settings.loadWithOverviewMode = true
|
||||
guiWebView.invokeZoomPicker()
|
||||
|
||||
// Disable cache! This is all local anyway
|
||||
guiWebView.settings.cacheMode = WebSettings.LOAD_NO_CACHE
|
||||
guiWebView.clearCache(true)
|
||||
|
||||
// Load GUI page
|
||||
guiWebView.loadUrl("http://127.0.0.1:$webServerPort/")
|
||||
guiWebView.loadUrl("https://slimevr.gui/")
|
||||
LogManager.info("[MainActivity] GUI WebView has been initialized and loaded.")
|
||||
|
||||
// Start a foreground service to notify the user the SlimeVR Server is running
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 133 B |
Binary file not shown.
|
Before Width: | Height: | Size: 3.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 642 B |
Binary file not shown.
|
Before Width: | Height: | Size: 940 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB |
Reference in New Issue
Block a user