feat: save dsp to keep config

This commit is contained in:
2026-10-24 11:55:45 +02:00
parent 8f1f221605
commit 364ebfc97f
5 changed files with 84 additions and 21 deletions
+34 -2
View File
@@ -8,15 +8,17 @@ import { useNotifications } from './hooks/useNotifications';
import Notifications from './components/Notifications/Notifications';
import CreditsPage from './pages/CreditsPage/CreditsPage';
import HomePage from './pages/HomePage/HomePage';
import { addDSP, createDSPInstance } from './dsp/dspApi';
import { addDSP, createDSPInstance, restoreDSPs } from './dsp/dspApi';
import { removeDSP } from './dsp/dspShared';
import { stopAllPolling } from './dsp/pollRegistry';
import { loadSavedDSPs, saveDSPs, toSaved } from './dsp/dspStorage';
import { DSPMode } from './features/dsp408/types';
function App() {
const [dsps, setDsps] = useState<DSP[]>([]);
const [selected, setSelected] = useState<number | null>(null);
const [page, setPage] = useState<AppPage>('home');
const [loaded, setLoaded] = useState(false);
const { notifications, notify, removeNotification, hoverNotification } = useNotifications();
const connectedDspCount = dsps.filter((dsp) => isConnected(dsp)).length;
@@ -29,6 +31,36 @@ function App() {
return () => stopAllPolling(dspsRef.current);
}, []);
// Load saved DSPs on startup
useEffect(() => {
let cancelled = false;
(async () => {
try {
const saved = await loadSavedDSPs();
const restored = await restoreDSPs(saved, notify);
if (!cancelled) setDsps(restored);
} catch (e) {
notify(`Failed to load saved DSPs: ${String(e)}`, 'error');
} finally {
if (!cancelled) setLoaded(true);
}
})();
return () => {
cancelled = true;
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
// Save only the config part, only after loading finished
const savedKey = JSON.stringify(dsps.map(toSaved));
useEffect(() => {
if (!loaded) return;
saveDSPs(dspsRef.current).catch((e) =>
notify(`Failed to save DSPs: ${String(e)}`, 'error')
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [savedKey, loaded]);
useEffect(() => {
if (activeDsp == null) return;
const instance = createDSPInstance(activeDsp, setDsps, notify);
@@ -83,4 +115,4 @@ function App() {
);
}
export default App;
export default App;