Have visualizer remember settings

This commit is contained in:
Jack Kingsman
2026-03-01 16:38:25 -08:00
parent e504f4de33
commit 18ac86b4c0
2 changed files with 137 additions and 12 deletions
+89
View File
@@ -0,0 +1,89 @@
const VISUALIZER_SETTINGS_KEY = 'remoteterm-visualizer-settings';
export interface VisualizerSettings {
showAmbiguousPaths: boolean;
showAmbiguousNodes: boolean;
useAdvertPathHints: boolean;
splitAmbiguousByTraffic: boolean;
chargeStrength: number;
observationWindowSec: number;
letEmDrift: boolean;
particleSpeedMultiplier: number;
pruneStaleNodes: boolean;
autoOrbit: boolean;
showControls: boolean;
}
export const VISUALIZER_DEFAULTS: VisualizerSettings = {
showAmbiguousPaths: true,
showAmbiguousNodes: false,
useAdvertPathHints: true,
splitAmbiguousByTraffic: true,
chargeStrength: -200,
observationWindowSec: 15,
letEmDrift: true,
particleSpeedMultiplier: 2,
pruneStaleNodes: false,
autoOrbit: false,
showControls: true,
};
export function getVisualizerSettings(): VisualizerSettings {
try {
const raw = localStorage.getItem(VISUALIZER_SETTINGS_KEY);
if (!raw) return { ...VISUALIZER_DEFAULTS };
const parsed = JSON.parse(raw) as Partial<VisualizerSettings>;
return {
showAmbiguousPaths:
typeof parsed.showAmbiguousPaths === 'boolean'
? parsed.showAmbiguousPaths
: VISUALIZER_DEFAULTS.showAmbiguousPaths,
showAmbiguousNodes:
typeof parsed.showAmbiguousNodes === 'boolean'
? parsed.showAmbiguousNodes
: VISUALIZER_DEFAULTS.showAmbiguousNodes,
useAdvertPathHints:
typeof parsed.useAdvertPathHints === 'boolean'
? parsed.useAdvertPathHints
: VISUALIZER_DEFAULTS.useAdvertPathHints,
splitAmbiguousByTraffic:
typeof parsed.splitAmbiguousByTraffic === 'boolean'
? parsed.splitAmbiguousByTraffic
: VISUALIZER_DEFAULTS.splitAmbiguousByTraffic,
chargeStrength:
typeof parsed.chargeStrength === 'number'
? parsed.chargeStrength
: VISUALIZER_DEFAULTS.chargeStrength,
observationWindowSec:
typeof parsed.observationWindowSec === 'number'
? parsed.observationWindowSec
: VISUALIZER_DEFAULTS.observationWindowSec,
letEmDrift:
typeof parsed.letEmDrift === 'boolean' ? parsed.letEmDrift : VISUALIZER_DEFAULTS.letEmDrift,
particleSpeedMultiplier:
typeof parsed.particleSpeedMultiplier === 'number'
? parsed.particleSpeedMultiplier
: VISUALIZER_DEFAULTS.particleSpeedMultiplier,
pruneStaleNodes:
typeof parsed.pruneStaleNodes === 'boolean'
? parsed.pruneStaleNodes
: VISUALIZER_DEFAULTS.pruneStaleNodes,
autoOrbit:
typeof parsed.autoOrbit === 'boolean' ? parsed.autoOrbit : VISUALIZER_DEFAULTS.autoOrbit,
showControls:
typeof parsed.showControls === 'boolean'
? parsed.showControls
: VISUALIZER_DEFAULTS.showControls,
};
} catch {
return { ...VISUALIZER_DEFAULTS };
}
}
export function saveVisualizerSettings(settings: VisualizerSettings): void {
try {
localStorage.setItem(VISUALIZER_SETTINGS_KEY, JSON.stringify(settings));
} catch {
// localStorage may be unavailable
}
}