Make vrc config save mute settings to config

This commit is contained in:
loucass003
2026-03-27 02:53:26 +01:00
parent 8168e1366a
commit fa1d2012e1
6 changed files with 40 additions and 13 deletions

View File

@@ -19,6 +19,7 @@ private const val SETTINGS_CONFIG_VERSION = 1
@Serializable
data class SettingsConfigState(
val trackerPort: Int = 6969,
val mutedVRCWarnings: List<String> = 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
}

View File

@@ -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
}

View File

@@ -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<String>,
val mutedWarnings: List<String>,
)
sealed interface VRCConfigActions {
@@ -40,10 +47,11 @@ sealed interface VRCConfigActions {
}
typealias VRCConfigContext = Context<VRCConfigState, VRCConfigActions>
typealias VRCConfigBehaviour = BasicBehaviour<VRCConfigState, VRCConfigActions>
typealias VRCConfigBehaviour = CustomBehaviour<VRCConfigState, VRCConfigActions, VRCConfigManager>
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<VRCConfigValues?>,
): 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)
}
val manager = VRCConfigManager(context = context, userHeight = userHeight, config = config)
modules.map { it.observer }.forEach { it?.invoke(manager) }
return manager
}

View File

@@ -21,6 +21,7 @@ fun main(args: Array<String>) = 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() },
)

View File

@@ -96,7 +96,6 @@ internal fun linuxVRCConfigFlow(): Flow<solarxr_protocol.rpc.VRCConfigValues?> =
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.

View File

@@ -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
},
)
)