expose patttern storage commands.
This commit is contained in:
parent
2abc6bfb38
commit
c0b3648fd2
|
@ -6,6 +6,7 @@ use btleplug::{
|
||||||
};
|
};
|
||||||
pub use state::{CentralState, ChannelState, PeripheralItem};
|
pub use state::{CentralState, ChannelState, PeripheralItem};
|
||||||
use tauri::{async_runtime::RwLock, AppHandle, Emitter, State};
|
use tauri::{async_runtime::RwLock, AppHandle, Emitter, State};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bluetooth, errors,
|
bluetooth, errors,
|
||||||
|
@ -157,3 +158,31 @@ pub async fn save_pattern(
|
||||||
.map_err(|e| errors::AppError::StorageFailure(e.to_string()))?;
|
.map_err(|e| errors::AppError::StorageFailure(e.to_string()))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn get_pattern(
|
||||||
|
app_state: State<'_, Arc<RwLock<AppState>>>,
|
||||||
|
pattern_id: Uuid,
|
||||||
|
) -> Result<Option<Pattern>, errors::AppError> {
|
||||||
|
let state = app_state.read().await;
|
||||||
|
let pattern = state
|
||||||
|
.db
|
||||||
|
.get_pattern(&pattern_id)
|
||||||
|
.await
|
||||||
|
.map_err(|e| errors::AppError::StorageFailure(e.to_string()))?;
|
||||||
|
Ok(pattern)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn remove_pattern(
|
||||||
|
app_state: State<'_, Arc<RwLock<AppState>>>,
|
||||||
|
pattern_id: Uuid,
|
||||||
|
) -> Result<(), errors::AppError> {
|
||||||
|
let state = app_state.read().await;
|
||||||
|
state
|
||||||
|
.db
|
||||||
|
.remove_pattern(&pattern_id)
|
||||||
|
.await
|
||||||
|
.map_err(|e| errors::AppError::StorageFailure(e.to_string()))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
@ -66,7 +66,9 @@ pub fn run() {
|
||||||
cmd::start_scan_devices,
|
cmd::start_scan_devices,
|
||||||
cmd::stop_scan_devices,
|
cmd::stop_scan_devices,
|
||||||
cmd::list_patterns,
|
cmd::list_patterns,
|
||||||
cmd::save_pattern
|
cmd::save_pattern,
|
||||||
|
cmd::get_pattern,
|
||||||
|
cmd::remove_pattern
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user