simplify history slightly
This commit is contained in:
parent
1a2ec72fb4
commit
18f32c7c8d
4 changed files with 13 additions and 14 deletions
|
|
@ -60,7 +60,7 @@ pub async fn update_history_limit(
|
||||||
crate::settings::write_settings(&app, settings);
|
crate::settings::write_settings(&app, settings);
|
||||||
|
|
||||||
history_manager
|
history_manager
|
||||||
.update_history_limit(limit)
|
.update_history_limit()
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -162,10 +162,8 @@ pub fn run() {
|
||||||
TranscriptionManager::new(&app, model_manager.clone())
|
TranscriptionManager::new(&app, model_manager.clone())
|
||||||
.expect("Failed to initialize transcription manager"),
|
.expect("Failed to initialize transcription manager"),
|
||||||
);
|
);
|
||||||
let history_manager = Arc::new(
|
let history_manager =
|
||||||
HistoryManager::new(&app, settings.history_limit)
|
Arc::new(HistoryManager::new(&app).expect("Failed to initialize history manager"));
|
||||||
.expect("Failed to initialize history manager"),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add managers to Tauri's managed state
|
// Add managers to Tauri's managed state
|
||||||
app.manage(recording_manager.clone());
|
app.manage(recording_manager.clone());
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ use rusqlite::{params, Connection, OptionalExtension};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
||||||
use tauri::{App, AppHandle, Emitter, Manager};
|
use tauri::{App, AppHandle, Emitter, Manager};
|
||||||
use tauri_plugin_sql::{Migration, MigrationKind};
|
use tauri_plugin_sql::{Migration, MigrationKind};
|
||||||
|
|
||||||
|
|
@ -25,11 +24,10 @@ pub struct HistoryManager {
|
||||||
app_handle: AppHandle,
|
app_handle: AppHandle,
|
||||||
recordings_dir: PathBuf,
|
recordings_dir: PathBuf,
|
||||||
db_path: PathBuf,
|
db_path: PathBuf,
|
||||||
history_limit: AtomicUsize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HistoryManager {
|
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();
|
let app_handle = app.app_handle().clone();
|
||||||
|
|
||||||
// Create recordings directory in app data dir
|
// Create recordings directory in app data dir
|
||||||
|
|
@ -47,7 +45,6 @@ impl HistoryManager {
|
||||||
app_handle,
|
app_handle,
|
||||||
recordings_dir,
|
recordings_dir,
|
||||||
db_path,
|
db_path,
|
||||||
history_limit: AtomicUsize::new(history_limit),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize database
|
// Initialize database
|
||||||
|
|
@ -100,7 +97,7 @@ impl HistoryManager {
|
||||||
transcription_text: String,
|
transcription_text: String,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// If history limit is 0, do not save at all.
|
// 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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,7 +157,7 @@ impl HistoryManager {
|
||||||
entries.push(row?);
|
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 {
|
if entries.len() > limit {
|
||||||
let entries_to_delete = &entries[limit..];
|
let entries_to_delete = &entries[limit..];
|
||||||
|
|
||||||
|
|
@ -308,8 +305,7 @@ impl HistoryManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_history_limit(&self, new_limit: usize) -> Result<()> {
|
pub fn update_history_limit(&self) -> Result<()> {
|
||||||
self.history_limit.swap(new_limit, Ordering::Relaxed);
|
|
||||||
self.cleanup_old_entries()?;
|
self.cleanup_old_entries()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -269,3 +269,8 @@ pub fn get_stored_binding(app: &AppHandle, id: &str) -> ShortcutBinding {
|
||||||
|
|
||||||
binding
|
binding
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_history_limit(app: &AppHandle) -> usize {
|
||||||
|
let settings = get_settings(app);
|
||||||
|
settings.history_limit
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue