state.rs
Language Rust1.1 KB35 lines
use std::collections::HashMap;use std::path::PathBuf;use std::sync::{Mutex, MutexGuard, PoisonError};use std::time::Instant;use cortex_core::secrets::KeyCache;use cortex_core::storage::Db;use tokio_util::sync::CancellationToken;pub struct AppState {pub db: Mutex<Db>,pub keys: KeyCache,pub streams: Mutex<HashMap<String, CancellationToken>>,pub data_dir: PathBuf,/// When the quick window was last shown; blur right after showing is ignored.pub quick_shown_at: Mutex<Option<Instant>>,/// While a native dialog is open, losing focus must not hide the quick window.pub dialog_open: Mutex<bool>,pub tray_spend: Mutex<Option<tauri::menu::MenuItem<tauri::Wry>>>,}/// Lock even if a panic elsewhere poisoned the mutex, so one failed command/// does not fail every later one until the app restarts.pub fn lock<T>(m: &Mutex<T>) -> MutexGuard<'_, T> {m.lock().unwrap_or_else(PoisonError::into_inner)}impl AppState {pub fn db(&self) -> MutexGuard<'_, Db> {lock(&self.db)}pub fn attachments_dir(&self) -> PathBuf {self.data_dir.join("attachments")}}