feat: remove state and let rust handle

This commit is contained in:
2026-09-12 19:37:59 +02:00
parent 2717dfe99a
commit 1e00ca3a7c
17 changed files with 221 additions and 1426 deletions
+28 -2
View File
@@ -41,16 +41,28 @@ impl AppState {
}
}
#[derive(serde::Serialize)]
pub struct DSP408Snapshot {
pub state: types::DSPState,
pub meters: types::Meters,
pub mode: types::DSPMode,
}
#[tauri::command]
pub fn create_dsp408(
state: State<AppState>,
ip: String,
port: u16,
device_id: u8,
demo: bool,
) -> Result<u64, String> {
let ip = IpAddr::from_str(&ip).map_err(|e| e.to_string())?;
let dsp = DSP408::new(ip, port, device_id).map_err(|e| e.to_string())?;
let dsp = if demo {
DSP408::new_demo()
} else {
DSP408::new(ip, port, device_id).map_err(|e| e.to_string())?
};
let mut next_id = state.next_id.lock().map_err(|e| e.to_string())?;
@@ -81,6 +93,20 @@ pub async fn remove_dsp408(state: State<'_, AppState>, id: u64) -> Result<(), St
Ok(())
}
#[tauri::command]
pub async fn get_dsp_snapshot(
state: State<'_, AppState>,
id: u64,
) -> Result<DSP408Snapshot, String> {
state.with_device_mut(id, |device| {
Ok(DSP408Snapshot {
state: device.dsp.state().clone(),
meters: device.dsp.meters().clone(),
mode: device.dsp.mode(),
})
})
}
#[tauri::command]
pub async fn connect_dsp408(state: State<'_, AppState>, id: u64) -> Result<(), String> {
state.with_device_mut(id, |device| device.dsp.connect().map_err(|e| e.to_string()))
@@ -99,7 +125,7 @@ pub async fn get_dsp_state(
id: u64,
) -> Result<dsp_thomann::dsp408::types::DSPState, String> {
state.with_device_mut(id, |device| {
let dsp_state = device.dsp.state().map_err(|e| e.to_string())?;
let dsp_state = device.dsp.state();
Ok(dsp_state.clone())
})