diff --git a/server/core/src/main/java/dev/slimevr/config/settings.kt b/server/core/src/main/java/dev/slimevr/config/settings.kt index 4a5aeea0f..8ccfb3af1 100644 --- a/server/core/src/main/java/dev/slimevr/config/settings.kt +++ b/server/core/src/main/java/dev/slimevr/config/settings.kt @@ -19,6 +19,7 @@ private const val SETTINGS_CONFIG_VERSION = 1 @Serializable data class SettingsConfigState( val trackerPort: Int = 6969, + val mutedVRCWarnings: List = listOf(), val version: Int = SETTINGS_CONFIG_VERSION, ) @@ -41,7 +42,7 @@ data class SettingsState( ) sealed interface SettingsActions { - data class Update(val transform: SettingsState.() -> SettingsState) : SettingsActions + data class Update(val transform: SettingsConfigState.() -> SettingsConfigState) : SettingsActions data class LoadProfile(val newState: SettingsState) : SettingsActions } @@ -57,7 +58,7 @@ data class Settings( val DefaultSettingsBehaviour = SettingsBehaviour( reducer = { s, a -> when (a) { - is SettingsActions.Update -> a.transform(s) + is SettingsActions.Update -> s.copy(data = a.transform(s.data)) is SettingsActions.LoadProfile -> a.newState else -> s } diff --git a/server/core/src/main/java/dev/slimevr/config/user.kt b/server/core/src/main/java/dev/slimevr/config/user.kt index 0d9553c01..1ae00c6f9 100644 --- a/server/core/src/main/java/dev/slimevr/config/user.kt +++ b/server/core/src/main/java/dev/slimevr/config/user.kt @@ -41,7 +41,7 @@ data class UserConfigState( ) sealed interface UserConfigActions { - data class Update(val transform: UserConfigState.() -> UserConfigState) : UserConfigActions + data class Update(val transform: UserConfigData.() -> UserConfigData) : UserConfigActions data class LoadProfile(val newState: UserConfigState) : UserConfigActions } @@ -57,7 +57,7 @@ data class UserConfig( val DefaultUserBehaviour = UserConfigBehaviour( reducer = { s, a -> when (a) { - is UserConfigActions.Update -> a.transform(s) + is UserConfigActions.Update -> s.copy(data = a.transform(s.data)) is UserConfigActions.LoadProfile -> a.newState else -> s } diff --git a/server/core/src/main/java/dev/slimevr/vrchat/module.kt b/server/core/src/main/java/dev/slimevr/vrchat/module.kt index 80aea5753..676316425 100644 --- a/server/core/src/main/java/dev/slimevr/vrchat/module.kt +++ b/server/core/src/main/java/dev/slimevr/vrchat/module.kt @@ -1,11 +1,18 @@ package dev.slimevr.vrchat import dev.slimevr.VRServer +import dev.slimevr.config.AppConfig +import dev.slimevr.config.SettingsActions import dev.slimevr.context.BasicBehaviour import dev.slimevr.context.Context +import dev.slimevr.context.CustomBehaviour import dev.slimevr.context.createContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import solarxr_protocol.datatypes.BodyPart import solarxr_protocol.rpc.VRCAvatarMeasurementType @@ -31,7 +38,7 @@ val VRC_VALID_KEYS = setOf( data class VRCConfigState( val currentValues: VRCConfigValues?, val isSupported: Boolean, - val mutedWarnings: Set, + val mutedWarnings: List, ) sealed interface VRCConfigActions { @@ -40,10 +47,11 @@ sealed interface VRCConfigActions { } typealias VRCConfigContext = Context -typealias VRCConfigBehaviour = BasicBehaviour +typealias VRCConfigBehaviour = CustomBehaviour data class VRCConfigManager( val context: VRCConfigContext, + val config: AppConfig, val userHeight: () -> Double, ) @@ -58,6 +66,14 @@ val DefaultVRCConfigBehaviour = VRCConfigBehaviour( } } }, + observer = { context -> + + context.context.state.map { it.mutedWarnings }.distinctUntilChanged().onEach { warnings -> + context.config.settings.context.dispatch(SettingsActions.Update { + copy(mutedVRCWarnings = warnings) + }) + }.launchIn(scope = context.context.scope) + } ) fun computeRecommendedValues(server: VRServer, userHeight: Double): VRCConfigRecommendedValues { @@ -104,20 +120,23 @@ fun computeValidity(values: VRCConfigValues, recommended: VRCConfigRecommendedVa ) fun createVRCConfigManager( + config: AppConfig, scope: CoroutineScope, userHeight: () -> Double, isSupported: Boolean, values: Flow, ): VRCConfigManager { + val modules = listOf(DefaultVRCConfigBehaviour) + val initialState = VRCConfigState( currentValues = null, isSupported = isSupported, - mutedWarnings = emptySet(), + mutedWarnings = listOf(), ) val context = createContext( initialState = initialState, - reducers = listOf(DefaultVRCConfigBehaviour.reducer), + reducers = modules.map { it.reducer }, scope = scope, ) @@ -125,5 +144,8 @@ fun createVRCConfigManager( values.collect { context.dispatch(VRCConfigActions.UpdateValues(it)) } } - return VRCConfigManager(context = context, userHeight = userHeight) -} \ No newline at end of file + val manager = VRCConfigManager(context = context, userHeight = userHeight, config = config) + modules.map { it.observer }.forEach { it?.invoke(manager) } + + return manager +} diff --git a/server/desktop/src/main/java/dev/slimevr/desktop/Main.kt b/server/desktop/src/main/java/dev/slimevr/desktop/Main.kt index 7fbea2153..11f2c740c 100644 --- a/server/desktop/src/main/java/dev/slimevr/desktop/Main.kt +++ b/server/desktop/src/main/java/dev/slimevr/desktop/Main.kt @@ -21,6 +21,7 @@ fun main(args: Array) = runBlocking { val serialServer = createDesktopSerialServer(this) val firmwareManager = createFirmwareManager(serialServer = serialServer, scope = this) val vrcConfigManager = createDesktopVRCConfigManager( + config = config, scope = this, userHeight = { config.userConfig.context.state.value.data.userHeight.toDouble() }, ) diff --git a/server/desktop/src/main/java/dev/slimevr/desktop/vrchat/linux.kt b/server/desktop/src/main/java/dev/slimevr/desktop/vrchat/linux.kt index c2fc7ab51..67e5a7034 100644 --- a/server/desktop/src/main/java/dev/slimevr/desktop/vrchat/linux.kt +++ b/server/desktop/src/main/java/dev/slimevr/desktop/vrchat/linux.kt @@ -96,7 +96,6 @@ internal fun linuxVRCConfigFlow(): Flow = intValue = { key -> keys[key]?.let { linuxGetDwordValue(registry, it) } }, doubleValue = { key -> keys[key]?.let { linuxGetQwordValue(registry, it) } }, )) - println("EMIT") } delay(3000) // it seems that on linux, steam writes to the reg file is unpredictable. diff --git a/server/desktop/src/main/java/dev/slimevr/desktop/vrchat/vrc-config.kt b/server/desktop/src/main/java/dev/slimevr/desktop/vrchat/vrc-config.kt index d049825f5..7bb0af89f 100644 --- a/server/desktop/src/main/java/dev/slimevr/desktop/vrchat/vrc-config.kt +++ b/server/desktop/src/main/java/dev/slimevr/desktop/vrchat/vrc-config.kt @@ -2,6 +2,7 @@ package dev.slimevr.desktop.vrchat import dev.slimevr.CURRENT_PLATFORM import dev.slimevr.Platform +import dev.slimevr.config.AppConfig import dev.slimevr.vrchat.VRCConfigManager import dev.slimevr.vrchat.createVRCConfigManager import kotlinx.coroutines.CoroutineScope @@ -13,21 +14,24 @@ import solarxr_protocol.rpc.VRCTrackerModel internal const val VRC_REG_PATH = "Software\\VRChat\\VRChat" -fun createDesktopVRCConfigManager(scope: CoroutineScope, userHeight: () -> Double): VRCConfigManager = +fun createDesktopVRCConfigManager(config: AppConfig, scope: CoroutineScope, userHeight: () -> Double): VRCConfigManager = when (CURRENT_PLATFORM) { Platform.WINDOWS -> createVRCConfigManager( + config = config, scope = scope, userHeight = userHeight, isSupported = true, values = windowsVRCConfigFlow(), ) Platform.LINUX -> createVRCConfigManager( + config = config, scope = scope, userHeight = userHeight, isSupported = true, values = linuxVRCConfigFlow(), ) else -> createVRCConfigManager( + config = config, scope = scope, userHeight = userHeight, isSupported = false, @@ -63,4 +67,4 @@ internal suspend fun buildVRCConfigValues( 1 -> VRCAvatarMeasurementType.HEIGHT else -> VRCAvatarMeasurementType.UNKNOWN }, -) \ No newline at end of file +)