29 lines
709 B
Rust
29 lines
709 B
Rust
use std::path::PathBuf;
|
|
use std::sync::Mutex;
|
|
|
|
use rusqlite::Connection;
|
|
|
|
use crate::db;
|
|
use crate::llama::LlamaManager;
|
|
|
|
/// Shared application state managed by Tauri.
|
|
pub struct AppState {
|
|
pub db: Mutex<Connection>,
|
|
pub data_dir: PathBuf,
|
|
}
|
|
|
|
impl AppState {
|
|
pub fn new() -> Result<Self, String> {
|
|
let data_dir = LlamaManager::data_dir();
|
|
std::fs::create_dir_all(&data_dir).map_err(|e| format!("Cannot create data dir: {e}"))?;
|
|
|
|
let db_path = data_dir.join("voice_to_notes.db");
|
|
let conn = db::open_database(&db_path).map_err(|e| format!("Cannot open database: {e}"))?;
|
|
|
|
Ok(Self {
|
|
db: Mutex::new(conn),
|
|
data_dir,
|
|
})
|
|
}
|
|
}
|