1- import { useEffect , useState } from "react" ;
1+ import { useEffect , useMemo , useState } from "react" ;
22import { AudioSettings , DeviceInventory , fromSelectValue , toNumber , toSelectValue } from "../model" ;
33import { LabeledNumberInput } from "../components/labeled-input" ;
44
@@ -9,22 +9,67 @@ type DevicesPageProps = {
99 onRefreshDevices : ( ) => void ;
1010} ;
1111
12+ const DEVICE_UI_STORAGE_KEY = "pawdio-lab-device-ui-v1" ;
13+
14+ type DeviceUiPrefs = {
15+ appearanceMode : string ;
16+ accentColor : string ;
17+ experimentalEnabled : boolean ;
18+ inputBitDepth : string ;
19+ } ;
20+
21+ function readDeviceUiPrefs ( ) : DeviceUiPrefs | null {
22+ if ( typeof window === "undefined" ) {
23+ return null ;
24+ }
25+ try {
26+ const raw = window . localStorage . getItem ( DEVICE_UI_STORAGE_KEY ) ;
27+ if ( ! raw ) {
28+ return null ;
29+ }
30+ const parsed = JSON . parse ( raw ) ;
31+ if ( ! parsed || typeof parsed !== "object" || Array . isArray ( parsed ) ) {
32+ return null ;
33+ }
34+ return parsed as DeviceUiPrefs ;
35+ } catch {
36+ return null ;
37+ }
38+ }
39+
1240export function DevicesPage ( {
1341 inventory,
1442 settings,
1543 onCommitSettings,
1644 onRefreshDevices
1745} : DevicesPageProps ) {
46+ const storedUiPrefs = useMemo ( ( ) => readDeviceUiPrefs ( ) , [ ] ) ;
1847 const [ draft , setDraft ] = useState ( settings ) ;
19- const [ appearanceMode , setAppearanceMode ] = useState ( "Dark" ) ;
20- const [ accentColor , setAccentColor ] = useState ( "Blue" ) ;
21- const [ experimentalEnabled , setExperimentalEnabled ] = useState ( true ) ;
22- const [ inputBitDepth , setInputBitDepth ] = useState ( "Auto" ) ;
48+ const [ appearanceMode , setAppearanceMode ] = useState ( storedUiPrefs ?. appearanceMode ?? "Dark" ) ;
49+ const [ accentColor , setAccentColor ] = useState ( storedUiPrefs ?. accentColor ?? "Blue" ) ;
50+ const [ experimentalEnabled , setExperimentalEnabled ] = useState (
51+ storedUiPrefs ?. experimentalEnabled ?? true
52+ ) ;
53+ const [ inputBitDepth , setInputBitDepth ] = useState ( storedUiPrefs ?. inputBitDepth ?? "Auto" ) ;
2354
2455 useEffect ( ( ) => {
2556 setDraft ( settings ) ;
2657 } , [ settings ] ) ;
2758
59+ useEffect ( ( ) => {
60+ const snapshot : DeviceUiPrefs = {
61+ appearanceMode,
62+ accentColor,
63+ experimentalEnabled,
64+ inputBitDepth
65+ } ;
66+ try {
67+ localStorage . setItem ( DEVICE_UI_STORAGE_KEY , JSON . stringify ( snapshot ) ) ;
68+ } catch {
69+ // ignore storage write failures
70+ }
71+ } , [ appearanceMode , accentColor , experimentalEnabled , inputBitDepth ] ) ;
72+
2873 function commitDeviceSelection ( next : AudioSettings ) {
2974 setDraft ( next ) ;
3075 onCommitSettings ( next ) ;
0 commit comments