expose patttern storage commands.

This commit is contained in:
Vixalie 2025-03-11 08:50:29 +08:00
parent 2abc6bfb38
commit c0b3648fd2
2 changed files with 32 additions and 1 deletions

View File

@ -6,6 +6,7 @@ use btleplug::{
};
pub use state::{CentralState, ChannelState, PeripheralItem};
use tauri::{async_runtime::RwLock, AppHandle, Emitter, State};
use uuid::Uuid;
use crate::{
bluetooth, errors,
@ -157,3 +158,31 @@ pub async fn save_pattern(
.map_err(|e| errors::AppError::StorageFailure(e.to_string()))?;
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(())
}

View File

@ -66,7 +66,9 @@ pub fn run() {
cmd::start_scan_devices,
cmd::stop_scan_devices,
cmd::list_patterns,
cmd::save_pattern
cmd::save_pattern,
cmd::get_pattern,
cmd::remove_pattern
])
.run(tauri::generate_context!())
.expect("error while running tauri application");