mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-24 02:51:20 -08:00
Better event-dispatcher with liteners that die with scope
This commit is contained in:
1 parent
8e19542c82
commit
05fbf64ac3
35 files changed
+174
-174
No files matched your search
@@ -19,6 +19,7 @@ import io.github.axisangles.ktmath.Vector3
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -151,7 +152,8 @@ suspend fun handleDriverConnection(
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
||||
bridge.outbound.on<DriverBridgeOutbound.TrackerPosition> { event ->
|
||||
sendMsg(
|
||||
ProtobufMessage(
|
||||
@@ -167,7 +169,7 @@ suspend fun handleDriverConnection(
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
||||
bridge.outbound.on<DriverBridgeOutbound.TrackerStatus> { event ->
|
||||
sendMsg(
|
||||
@@ -190,7 +192,7 @@ suspend fun handleDriverConnection(
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
||||
sendMsg(ProtobufMessage(version = Version(protocol_version = PROTOCOL_VERSION)))
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.ktor.util.moveToByteArray
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.withContext
|
||||
import solarxr_protocol.MessageBundle
|
||||
import solarxr_protocol.rpc.EnableSteamVRDriverRequest
|
||||
@@ -35,7 +36,7 @@ class EnableSteamVRDriverBehaviour : SolarXRBridgeBehaviour {
|
||||
unblockSteamVRDriver(client, "slimevr")
|
||||
client.close()
|
||||
}
|
||||
}
|
||||
}.launchIn(receiver.context.scope)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +51,7 @@ class OpenKeybindSettingsBehaviour : SolarXRBridgeBehaviour {
|
||||
}.onFailure { AppLogger.keybind.error(it, "Failed to open global shortcuts settings") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}.launchIn(receiver.context.scope)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +78,7 @@ suspend fun handleSolarXRBridge(
|
||||
val fbb = FlatBufferBuilder(256)
|
||||
fbb.finish(bundle.encode(JvmFlatBufferWriter(fbb)))
|
||||
send(fbb.dataBuffer().moveToByteArray())
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
||||
try {
|
||||
messages.collect { bytes ->
|
||||
|
||||
@@ -75,7 +75,7 @@ private suspend fun setupWindowsKeybinds(appContext: AppContextProvider, scope:
|
||||
}
|
||||
|
||||
apply(appContext.config.settings.context.state.value.data.keybinds)
|
||||
appContext.keybindManager.events.on<KeybindEvent.Rebind> { apply(it.keybinds) }
|
||||
appContext.keybindManager.events.on<KeybindEvent.Rebind> { apply(it.keybinds) }.launchIn(scope)
|
||||
|
||||
appContext.keybindManager.context.state
|
||||
.map { it.recording }
|
||||
|
||||
Reference in new issue
Block a user