mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-21 09:31:20 -08:00
Start bindings provider when SteamVR driver handshakes via SolarXR
This commit is contained in:
3 files changed
+75
-59
No files matched your search
@@ -2,14 +2,13 @@ package dev.slimevr.desktop.ipc
|
||||
|
||||
import com.squareup.wire.ProtoWriter
|
||||
import dev.slimevr.AppContextProvider
|
||||
import dev.slimevr.CURRENT_PLATFORM
|
||||
import dev.slimevr.Platform
|
||||
import dev.slimevr.desktop.platform.Battery
|
||||
import dev.slimevr.desktop.platform.Position
|
||||
import dev.slimevr.desktop.platform.ProtobufMessage
|
||||
import dev.slimevr.desktop.platform.TrackerAdded
|
||||
import dev.slimevr.desktop.platform.TrackerStatus
|
||||
import dev.slimevr.desktop.platform.Version
|
||||
import dev.slimevr.desktop.startBindingsProvider
|
||||
import dev.slimevr.driver.DriverBridge
|
||||
import dev.slimevr.driver.DriverBridgeInbound
|
||||
import dev.slimevr.driver.DriverBridgeOutbound
|
||||
@@ -17,23 +16,15 @@ import dev.slimevr.driver.DriverBridgeSource
|
||||
import dev.slimevr.driver.TrackerRole
|
||||
import dev.slimevr.driver.bodyPartToRole
|
||||
import dev.slimevr.driver.roleToBodyPart
|
||||
import dev.slimevr.logging.AppLogger
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.cancelChildren
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
import okio.Buffer
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.exists
|
||||
|
||||
val solarxrToProtoStatus = mapOf(
|
||||
solarxr_protocol.datatypes.TrackerStatus.OK to TrackerStatus.Status.OK,
|
||||
@@ -54,54 +45,6 @@ val protoToSolarxrStatus = mapOf(
|
||||
|
||||
const val PROTOCOL_VERSION = 2
|
||||
|
||||
private fun getBindingsProviderPath(): Path? {
|
||||
val executableName = when (CURRENT_PLATFORM) {
|
||||
Platform.WINDOWS -> "SlimeVR-Bindings-Provider.exe"
|
||||
Platform.LINUX -> "slimevr-bindings-provider"
|
||||
else -> return null
|
||||
}
|
||||
|
||||
// First we want to try to find it in the working directory, its location on
|
||||
// Steam/Windows/portable.
|
||||
val workingDir = System.getProperty("user.dir")
|
||||
val binaryPath = Path(workingDir, executableName)
|
||||
if (binaryPath.exists()) return binaryPath
|
||||
|
||||
// Then look through PATH to find the binary.
|
||||
// PATH shouldn't be null, but if it is just gracefully fail
|
||||
val path = System.getenv("PATH") ?: return null
|
||||
for (path in path.split(File.pathSeparator)) {
|
||||
val binaryPath = Path(path, executableName)
|
||||
if (binaryPath.exists()) return binaryPath
|
||||
}
|
||||
|
||||
// :(
|
||||
return null
|
||||
}
|
||||
|
||||
suspend fun startBindingProvider() = withContext(Dispatchers.IO) {
|
||||
val path = getBindingsProviderPath()
|
||||
if (path == null) {
|
||||
AppLogger.steamvr.warn("Failed to find bindings provider")
|
||||
return@withContext
|
||||
}
|
||||
|
||||
AppLogger.steamvr.info("Found bindings provider at $path")
|
||||
// Give SteamVR a bit more time to initialise everything
|
||||
// For some users, starting the executable immediately may cause startup failures
|
||||
delay(3000L)
|
||||
val proc = try {
|
||||
ProcessBuilder(path.toString()).start()
|
||||
} catch (e: Exception) {
|
||||
AppLogger.steamvr.error(e, "Failed to start bindings provider")
|
||||
return@withContext
|
||||
}
|
||||
AppLogger.steamvr.info("Started bindings provider (PID ${proc.pid()})")
|
||||
proc.waitFor()
|
||||
|
||||
AppLogger.steamvr.info("Bindings provider exited with code ${proc.exitValue()}")
|
||||
}
|
||||
|
||||
suspend fun handleDriverConnection(
|
||||
appContext: AppContextProvider,
|
||||
source: DriverBridgeSource,
|
||||
@@ -189,7 +132,7 @@ suspend fun handleDriverConnection(
|
||||
// FIXME: multiple launch could be created here bc nothing prevent protocol from changing or getting called again during runtime
|
||||
// causing a memory leak
|
||||
this@coroutineScope.launch {
|
||||
startBindingProvider()
|
||||
startBindingsProvider()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,19 @@ import dev.slimevr.CURRENT_PLATFORM
|
||||
import dev.slimevr.Platform
|
||||
import dev.slimevr.SLIMEVR_IDENTIFIER
|
||||
import dev.slimevr.VRServerActions
|
||||
import dev.slimevr.desktop.startBindingsProvider
|
||||
import dev.slimevr.desktop.unblockSteamVRDriver
|
||||
import dev.slimevr.fbscodegen.runtime.JvmFlatBufferReader
|
||||
import dev.slimevr.fbscodegen.runtime.JvmFlatBufferWriter
|
||||
import dev.slimevr.logging.AppLogger
|
||||
import dev.slimevr.solarxr.SolarXRBridge
|
||||
import dev.slimevr.solarxr.SolarXRBridgeActions
|
||||
import dev.slimevr.solarxr.SolarXRBridgeBehaviour
|
||||
import dev.slimevr.solarxr.SolarXRBridgeState
|
||||
import dev.slimevr.solarxr.onSolarXRMessage
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.cio.CIO
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.cancelChildren
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
@@ -55,6 +59,18 @@ class OpenKeybindSettingsBehaviour : SolarXRBridgeBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
class OpenBindingsProviderBehaviour(val scope: CoroutineScope) : SolarXRBridgeBehaviour {
|
||||
override fun reduce(
|
||||
state: SolarXRBridgeState,
|
||||
action: SolarXRBridgeActions,
|
||||
): SolarXRBridgeState {
|
||||
if (action is SolarXRBridgeActions.SetDriverInfo && action.name == "SteamVR") {
|
||||
scope.launch { startBindingsProvider() }
|
||||
}
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun handleSolarXRBridge(
|
||||
appContext: AppContextProvider,
|
||||
messages: Flow<Buffer>,
|
||||
@@ -68,6 +84,7 @@ suspend fun handleSolarXRBridge(
|
||||
buildList {
|
||||
add(EnableSteamVRDriverBehaviour())
|
||||
add(OpenKeybindSettingsBehaviour())
|
||||
add(OpenBindingsProviderBehaviour(this@coroutineScope))
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.slimevr.desktop
|
||||
|
||||
import dev.slimevr.CURRENT_PLATFORM
|
||||
import dev.slimevr.Platform
|
||||
import dev.slimevr.logging.AppLogger
|
||||
import dev.slimevr.tryOpenUri
|
||||
import io.ktor.client.HttpClient
|
||||
@@ -10,10 +12,16 @@ import io.ktor.client.request.request
|
||||
import io.ktor.client.request.setBody
|
||||
import io.ktor.http.HttpMethod
|
||||
import io.ktor.http.isSuccess
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.exists
|
||||
|
||||
@Serializable
|
||||
data class DriverManifest(
|
||||
@@ -100,3 +108,51 @@ suspend fun unblockSteamVRDriver(client: HttpClient, driver: String) {
|
||||
|
||||
tryOpenUri("vrmonitor://restartsystem")
|
||||
}
|
||||
|
||||
private fun getBindingsProviderPath(): Path? {
|
||||
val executableName = when (CURRENT_PLATFORM) {
|
||||
Platform.WINDOWS -> "SlimeVR-Bindings-Provider.exe"
|
||||
Platform.LINUX -> "slimevr-bindings-provider"
|
||||
else -> return null
|
||||
}
|
||||
|
||||
// First we want to try to find it in the working directory, its location on
|
||||
// Steam/Windows/portable.
|
||||
val workingDir = System.getProperty("user.dir")
|
||||
val binaryPath = Path(workingDir, executableName)
|
||||
if (binaryPath.exists()) return binaryPath
|
||||
|
||||
// Then look through PATH to find the binary.
|
||||
// PATH shouldn't be null, but if it is just gracefully fail
|
||||
val path = System.getenv("PATH") ?: return null
|
||||
for (path in path.split(File.pathSeparator)) {
|
||||
val binaryPath = Path(path, executableName)
|
||||
if (binaryPath.exists()) return binaryPath
|
||||
}
|
||||
|
||||
// :(
|
||||
return null
|
||||
}
|
||||
|
||||
suspend fun startBindingsProvider() = withContext(Dispatchers.IO) {
|
||||
val path = getBindingsProviderPath()
|
||||
if (path == null) {
|
||||
AppLogger.steamvr.warn("Failed to find bindings provider")
|
||||
return@withContext
|
||||
}
|
||||
|
||||
AppLogger.steamvr.info("Found bindings provider at $path")
|
||||
// Give SteamVR a bit more time to initialise everything
|
||||
// For some users, starting the executable immediately may cause startup failures
|
||||
delay(3000L)
|
||||
val proc = try {
|
||||
ProcessBuilder(path.toString()).start()
|
||||
} catch (e: Exception) {
|
||||
AppLogger.steamvr.error(e, "Failed to start bindings provider")
|
||||
return@withContext
|
||||
}
|
||||
AppLogger.steamvr.info("Started bindings provider (PID ${proc.pid()})")
|
||||
proc.waitFor()
|
||||
|
||||
AppLogger.steamvr.info("Bindings provider exited with code ${proc.exitValue()}")
|
||||
}
|
||||
Reference in new issue
Block a user