Handy/src-tauri/src/commands/history.rs
CJ Pais 9521ab9332
WIP: Add tauri-specta for generating TS bindings (#322)
* initial specta commands

* refactor to use the bindings in the ui

* merge fixes

* remove unused commands

* add clamshell to lib

* Remove Invoke from everything.

* fix settings not being loaded properly

* fix settings being overwritten due to deserialization failure + remove
provider kind

* fix model loading text bug
2025-11-27 17:07:22 +07:00

101 lines
2.7 KiB
Rust

use crate::managers::history::{HistoryEntry, HistoryManager};
use std::sync::Arc;
use tauri::{AppHandle, State};
#[tauri::command]
#[specta::specta]
pub async fn get_history_entries(
_app: AppHandle,
history_manager: State<'_, Arc<HistoryManager>>,
) -> Result<Vec<HistoryEntry>, String> {
history_manager
.get_history_entries()
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
#[specta::specta]
pub async fn toggle_history_entry_saved(
_app: AppHandle,
history_manager: State<'_, Arc<HistoryManager>>,
id: i64,
) -> Result<(), String> {
history_manager
.toggle_saved_status(id)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
#[specta::specta]
pub async fn get_audio_file_path(
_app: AppHandle,
history_manager: State<'_, Arc<HistoryManager>>,
file_name: String,
) -> Result<String, String> {
let path = history_manager.get_audio_file_path(&file_name);
path.to_str()
.ok_or_else(|| "Invalid file path".to_string())
.map(|s| s.to_string())
}
#[tauri::command]
#[specta::specta]
pub async fn delete_history_entry(
_app: AppHandle,
history_manager: State<'_, Arc<HistoryManager>>,
id: i64,
) -> Result<(), String> {
history_manager
.delete_entry(id)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
#[specta::specta]
pub async fn update_history_limit(
app: AppHandle,
history_manager: State<'_, Arc<HistoryManager>>,
limit: usize,
) -> Result<(), String> {
let mut settings = crate::settings::get_settings(&app);
settings.history_limit = limit;
crate::settings::write_settings(&app, settings);
history_manager
.cleanup_old_entries()
.map_err(|e| e.to_string())?;
Ok(())
}
#[tauri::command]
#[specta::specta]
pub async fn update_recording_retention_period(
app: AppHandle,
history_manager: State<'_, Arc<HistoryManager>>,
period: String,
) -> Result<(), String> {
use crate::settings::RecordingRetentionPeriod;
let retention_period = match period.as_str() {
"never" => RecordingRetentionPeriod::Never,
"preserve_limit" => RecordingRetentionPeriod::PreserveLimit,
"days3" => RecordingRetentionPeriod::Days3,
"weeks2" => RecordingRetentionPeriod::Weeks2,
"months3" => RecordingRetentionPeriod::Months3,
_ => return Err(format!("Invalid retention period: {}", period)),
};
let mut settings = crate::settings::get_settings(&app);
settings.recording_retention_period = retention_period;
crate::settings::write_settings(&app, settings);
history_manager
.cleanup_old_entries()
.map_err(|e| e.to_string())?;
Ok(())
}