Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions gui/src/components/settings/pages/GeneralSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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();
Expand All @@ -183,7 +195,10 @@ export function GeneralSettings() {
const { reset, control, watch, handleSubmit, getValues, setValue } =
useForm<SettingsForm>({
defaultValues,
mode: 'onChange',
reValidateMode: 'onChange',
});

const {
trackers: {
automaticTrackerToggle,
Expand Down Expand Up @@ -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<boolean | null>(null);
useRPCPacket(RpcMessage.SettingsResponse, (settings: SettingsResponseT) => {
useEffect(() => {
const formData: DefaultValues<SettingsForm> = {};

if (settings.filtering) {
Expand Down Expand Up @@ -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<boolean | null>(null);
useRPCPacket(RpcMessage.SettingsResponse, (settings: SettingsResponseT) => {
setSettings(settings);
});

useEffect(() => {
Expand All @@ -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 (
<SettingsPageLayout>
<HandsWarningModal
Expand Down
15 changes: 6 additions & 9 deletions server/core/src/main/java/dev/slimevr/VRServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,8 @@ class VRServer @JvmOverloads constructor(
queueTask {
humanPoseManager.updateSkeletonModelFromServer()
vrcOSCHandler.setHeadTracker(TrackerUtils.getTrackerForSkeleton(trackers, TrackerPosition.HEAD))
if (this.getVRBridge(ISteamVRBridge::class.java)?.updateShareSettingsAutomatically() == true) {
RPCSettingsHandler.sendSteamVRUpdatedSettings(protocolAPI, protocolAPI.rpcHandler)
}
this.getVRBridge(ISteamVRBridge::class.java)?.updateShareSettingsAutomatically()
RPCSettingsHandler.sendSteamVRUpdatedSettings(protocolAPI, protocolAPI.rpcHandler)
}
}

Expand All @@ -329,19 +328,17 @@ class VRServer @JvmOverloads constructor(
queueTask {
humanPoseManager.setPauseTracking(pauseTracking, sourceName)
// Toggle trackers as they don't toggle when tracking is paused
if (this.getVRBridge(ISteamVRBridge::class.java)?.updateShareSettingsAutomatically() == true) {
RPCSettingsHandler.sendSteamVRUpdatedSettings(protocolAPI, protocolAPI.rpcHandler)
}
this.getVRBridge(ISteamVRBridge::class.java)?.updateShareSettingsAutomatically()
RPCSettingsHandler.sendSteamVRUpdatedSettings(protocolAPI, protocolAPI.rpcHandler)
}
}

fun togglePauseTracking(sourceName: String?) {
queueTask {
humanPoseManager.togglePauseTracking(sourceName)
// Toggle trackers as they don't toggle when tracking is paused
if (this.getVRBridge(ISteamVRBridge::class.java)?.updateShareSettingsAutomatically() == true) {
RPCSettingsHandler.sendSteamVRUpdatedSettings(protocolAPI, protocolAPI.rpcHandler)
}
this.getVRBridge(ISteamVRBridge::class.java)?.updateShareSettingsAutomatically()
RPCSettingsHandler.sendSteamVRUpdatedSettings(protocolAPI, protocolAPI.rpcHandler)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class RPCSettingsHandler(var rpcHandler: RPCHandler, var api: ProtocolAPI) {
bridge.changeShareSettings(TrackerRole.LEFT_HAND, req.steamVrTrackers().leftHand())
bridge.changeShareSettings(TrackerRole.RIGHT_HAND, req.steamVrTrackers().rightHand())
bridge.setAutomaticSharedTrackers(req.steamVrTrackers().automaticTrackerToggle())
sendSteamVRUpdatedSettings(api, rpcHandler)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ abstract class SteamVRBridge(
if (value == config.automaticSharedTrackersToggling) return

config.automaticSharedTrackersToggling = value
if (value) {
updateShareSettingsAutomatically()
RPCSettingsHandler.sendSteamVRUpdatedSettings(instance.protocolAPI, instance.protocolAPI.rpcHandler)
}
updateShareSettingsAutomatically()
instance.configManager.saveConfig()
}

Expand Down