From f4646f11331abcf9e1ee2c4448ec3058f97cea3f Mon Sep 17 00:00:00 2001 From: Sapphire Date: Thu, 16 Apr 2026 01:56:22 -0500 Subject: [PATCH] Send SteamVRTrackersSetting when changing tracker toggles (#1778) Co-authored-by: loucass003 --- .../settings/pages/GeneralSettings.tsx | 39 +++++++++++-------- .../src/main/java/dev/slimevr/VRServer.kt | 15 +++---- .../rpc/settings/RPCSettingsHandler.kt | 1 + .../slimevr/desktop/platform/SteamVRBridge.kt | 5 +-- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/gui/src/components/settings/pages/GeneralSettings.tsx b/gui/src/components/settings/pages/GeneralSettings.tsx index 9a14ff3e7..d9907ce0f 100644 --- a/gui/src/components/settings/pages/GeneralSettings.tsx +++ b/gui/src/components/settings/pages/GeneralSettings.tsx @@ -43,6 +43,9 @@ import { loadResetSettings, ResetSettingsForm, } from '@/hooks/reset-settings'; +import { atom, useAtomValue, useSetAtom } from 'jotai'; +import { isEqual } from '@react-hookz/deep-equal'; +import { selectAtom } from 'jotai/utils'; export type SettingsForm = { trackers: { @@ -163,7 +166,16 @@ const defaultValues: SettingsForm = { hidSettings: { trackersOverHID: false }, }; +const settingsAtom = atom(new SettingsResponseT()); +const settingsValueAtom = selectAtom( + settingsAtom, + (settings) => settings, + isEqual +); + export function GeneralSettings() { + const setSettings = useSetAtom(settingsAtom); + const settings = useAtomValue(settingsValueAtom); const { l10n } = useLocalization(); const { config } = useConfig(); const { currentLocales } = useLocaleConfig(); @@ -183,7 +195,10 @@ export function GeneralSettings() { const { reset, control, watch, handleSubmit, getValues, setValue } = useForm({ defaultValues, + mode: 'onChange', + reValidateMode: 'onChange', }); + const { trackers: { automaticTrackerToggle, @@ -302,10 +317,7 @@ export function GeneralSettings() { sendRPCPacket(RpcMessage.SettingsRequest, new SettingsRequestT()); }, []); - // If null, we still haven't shown the hands warning - // if false then initially the hands warning was disabled - const [handsWarning, setHandsWarning] = useState(null); - useRPCPacket(RpcMessage.SettingsResponse, (settings: SettingsResponseT) => { + useEffect(() => { const formData: DefaultValues = {}; if (settings.filtering) { @@ -408,6 +420,13 @@ export function GeneralSettings() { } reset({ ...getValues(), ...formData }); + }, [settings]); + + // If null, we still haven't shown the hands warning + // if false then initially the hands warning was disabled + const [handsWarning, setHandsWarning] = useState(null); + useRPCPacket(RpcMessage.SettingsResponse, (settings: SettingsResponseT) => { + setSettings(settings); }); useEffect(() => { @@ -421,18 +440,6 @@ export function GeneralSettings() { } }, [steamVrLeftHand, steamVrRightHand, handsWarning]); - // Handle scrolling to selected page - // useEffect(() => { - // const typedState: { scrollTo: string } = state as any; - // if (!pageRef.current || !typedState || !typedState.scrollTo) { - // return; - // } - // const elem = pageRef.current.querySelector(`#${typedState.scrollTo}`); - // if (elem) { - // elem.scrollIntoView({ behavior: 'smooth' }); - // } - // }, [state]); - return (