A free, open source, and extensible speech-to-text application that works completely offline.
simplify history slightly
CJ Pais18f32c7c8db9
diff --git a/src-tauri/src/commands/history.rs b/src-tauri/src/commands/history.rsindex 98579605..888b98f2 100644--- a/src-tauri/src/commands/history.rs+++ b/src-tauri/src/commands/history.rs@@ -60,7 +60,7 @@ pub async fn update_history_limit(crate::settings::write_settings(&app, settings);history_manager- .update_history_limit(limit)+ .update_history_limit().map_err(|e| e.to_string())?;Ok(())diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex 7d861236..c3070015 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -162,10 +162,8 @@ pub fn run() {TranscriptionManager::new(&app, model_manager.clone()).expect("Failed to initialize transcription manager"),);- let history_manager = Arc::new(- HistoryManager::new(&app, settings.history_limit)- .expect("Failed to initialize history manager"),- );+ let history_manager =+ Arc::new(HistoryManager::new(&app).expect("Failed to initialize history manager"));// Add managers to Tauri's managed stateapp.manage(recording_manager.clone());diff --git a/src-tauri/src/managers/history.rs b/src-tauri/src/managers/history.rsindex 57a2d4b4..402da90b 100644--- a/src-tauri/src/managers/history.rs+++ b/src-tauri/src/managers/history.rs@@ -5,7 +5,6 @@ use rusqlite::{params, Connection, OptionalExtension};use serde::{Deserialize, Serialize};use std::fs;use std::path::PathBuf;-use std::sync::atomic::{AtomicUsize, Ordering};use tauri::{App, AppHandle, Emitter, Manager};use tauri_plugin_sql::{Migration, MigrationKind};@@ -25,11 +24,10 @@ pub struct HistoryManager {app_handle: AppHandle,recordings_dir: PathBuf,db_path: PathBuf,- history_limit: AtomicUsize,}impl HistoryManager {- pub fn new(app: &App, history_limit: usize) -> Result<Self> {+ pub fn new(app: &App) -> Result<Self> {let app_handle = app.app_handle().clone();// Create recordings directory in app data dir@@ -47,7 +45,6 @@ impl HistoryManager {app_handle,recordings_dir,db_path,- history_limit: AtomicUsize::new(history_limit),};// Initialize database@@ -100,7 +97,7 @@ impl HistoryManager {transcription_text: String,) -> Result<()> {// If history limit is 0, do not save at all.- if self.history_limit.load(Ordering::Relaxed) == 0 {+ if crate::settings::get_history_limit(&self.app_handle) == 0 {return Ok(());}@@ -160,7 +157,7 @@ impl HistoryManager {entries.push(row?);}- let limit = self.history_limit.load(Ordering::Relaxed);+ let limit = crate::settings::get_history_limit(&self.app_handle);if entries.len() > limit {let entries_to_delete = &entries[limit..];@@ -247,7 +244,7 @@ impl HistoryManager {pub async fn get_entry_by_id(&self, id: i64) -> Result<Option<HistoryEntry>> {let conn = self.get_connection()?;let mut stmt = conn.prepare(- "SELECT id, file_name, timestamp, saved, title, transcription_text+ "SELECT id, file_name, timestamp, saved, title, transcription_textFROM transcription_history WHERE id = ?1",)?;@@ -308,8 +305,7 @@ impl HistoryManager {}}- pub fn update_history_limit(&self, new_limit: usize) -> Result<()> {- self.history_limit.swap(new_limit, Ordering::Relaxed);+ pub fn update_history_limit(&self) -> Result<()> {self.cleanup_old_entries()?;Ok(())}diff --git a/src-tauri/src/settings.rs b/src-tauri/src/settings.rsindex 693f4ff6..9599ef75 100644--- a/src-tauri/src/settings.rs+++ b/src-tauri/src/settings.rs@@ -269,3 +269,8 @@ pub fn get_stored_binding(app: &AppHandle, id: &str) -> ShortcutBinding {binding}++pub fn get_history_limit(app: &AppHandle) -> usize {+ let settings = get_settings(app);+ settings.history_limit+}