This commit is contained in:
Lucas
2026-09-29 16:59:54 +02:00
parent d5a2afdea5
commit 6511d9d007
7 changed files with 57 additions and 36 deletions
+10 -12
View File
@@ -12,6 +12,7 @@ import {
PEQBand,
InputSource,
DSP408Snapshot,
DSPMode,
} from './types';
import { SetDsps, NotifyFn, updateDSP, setPollingPaused } from '../../dsp/dspShared';
import { registerPollStopper } from '../../dsp/pollRegistry';
@@ -117,8 +118,8 @@ export async function create(params: {
ip: params.ip,
port: params.port,
deviceId: params.deviceId,
mode: snapshot.mode,
status: 'disconnected',
mode: params.demo ? DSPMode.Demo: DSPMode.Normal,
isConnecting: false,
pollingPaused: true,
state: snapshot.state,
input_meters: snapshot.input_meters,
@@ -130,6 +131,7 @@ export function forDSP408(dsp: DSP408, setDsps: SetDsps, notify: NotifyFn) {
async function updateDSPState(): Promise<DSP408['state']> {
try {
const state = await invoke<DSP408['state']>('get_dsp_state', { id: dsp.id });
updateDSP(setDsps, dsp.id, (d) => ({ ...d, state }) as DSP408);
return state;
@@ -143,11 +145,11 @@ export function forDSP408(dsp: DSP408, setDsps: SetDsps, notify: NotifyFn) {
async function abortLocked() {
await invoke('disconnect_dsp408', { id: dsp.id }).catch(() => {});
updateDSP(setDsps, dsp.id, (d) => ({ ...d, status: 'disconnected', passwordRequired: true }));
updateDSP(setDsps, dsp.id, (d) => ({ ...d, passwordRequired: true }));
}
async function connectInternal(password?: string) {
updateDSP(setDsps, dsp.id, (d) => ({ ...d, status: 'connecting', passwordRequired: false }));
updateDSP(setDsps, dsp.id, (d) => ({ ...d, isConnecting: true, passwordRequired: false }));
try {
await invoke('connect_dsp408', { id: dsp.id });
@@ -159,13 +161,10 @@ export function forDSP408(dsp: DSP408, setDsps: SetDsps, notify: NotifyFn) {
return;
}
try {
await invoke('unlock_device', { id: dsp.id, password }); // adjust name/signature
} catch {
// wrong password
}
let r = await invoke('unlock_device', { id: dsp.id, password });
state = await updateDSPState();
if (isLocked(state)) {
await abortLocked();
notify('Wrong password', 'error', dsp.name);
@@ -173,11 +172,11 @@ export function forDSP408(dsp: DSP408, setDsps: SetDsps, notify: NotifyFn) {
}
}
updateDSP(setDsps, dsp.id, (d) => ({ ...d, status: 'connected', pollingPaused: false }));
updateDSP(setDsps, dsp.id, (d) => ({ ...d, isConnecting: false, pollingPaused: false }));
notify('Connected', 'success', dsp.name);
startPolling(dsp, setDsps);
} catch (err) {
updateDSP(setDsps, dsp.id, (d) => ({ ...d, status: 'disconnected' }));
updateDSP(setDsps, dsp.id, (d) => ({ ...d, isConnecting: false }));
notify(`Connection failed: ${String(err)}`, 'error', dsp.name);
}
}
@@ -216,7 +215,6 @@ export function forDSP408(dsp: DSP408, setDsps: SetDsps, notify: NotifyFn) {
updateDSP(setDsps, dsp.id, (d) => ({
...d,
status: 'disconnected',
pollingPaused: true,
}));