Files
creddy/src/session.rs
T
2026-11-18 10:14:36 -05:00

49 lines
1.0 KiB
Rust

use gpui_kit::Global;
use crate::config::AppConfig;
use crate::error::CreddyError;
use crate::db::Db;
#[derive(Debug)]
pub enum AppSession {
Empty,
Locked,
Unlocked(Db),
}
impl AppSession {
pub fn load(config: &AppConfig) -> AppSession {
if config.db_path().exists() {
AppSession::Locked
} else {
AppSession::Empty
}
}
}
impl Global for AppSession {}
#[cfg(test)]
mod tests {
use super::*;
use std::assert_matches;
use testresult::TestResult;
use crate::test_data::TestEnv;
#[test]
fn test_load_empty() -> TestResult {
let env = TestEnv::new()?;
let session = AppSession::load(&env.config);
assert_matches!(session, AppSession::Empty);
Ok(())
}
#[test]
fn test_load_locked() -> TestResult {
let env = TestEnv::new()?;
let _ = env.db()?; // creates the database in the temp dir
let session = AppSession::load(&env.config);
assert_matches!(session, AppSession::Locked);
Ok(())
}
}