feat: remove state and let rust handle
This commit is contained in:
@@ -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())
|
||||
})
|
||||
|
||||
@@ -11,6 +11,7 @@ pub fn run() {
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
commands::create_dsp408,
|
||||
commands::remove_dsp408,
|
||||
commands::get_dsp_snapshot,
|
||||
commands::get_dsp_state,
|
||||
commands::connect_dsp408, // 0x10
|
||||
commands::disconnect_dsp408, // 0x11
|
||||
|
||||
Reference in New Issue
Block a user