refactor(v3): project-scoped ContextPane with auto-registration

This commit is contained in:
Hibryda 2026-03-08 04:13:41 +01:00
parent 0f0ea3fb59
commit e37c85e294
5 changed files with 139 additions and 147 deletions

View file

@ -141,6 +141,24 @@ impl CtxDb {
Ok(())
}
/// Register a project in the ctx database (creates if not exists).
pub fn register_project(&self, name: &str, description: &str, work_dir: Option<&str>) -> Result<(), String> {
let db_path = Self::db_path();
if !db_path.exists() {
return Err("ctx database not found".to_string());
}
let conn = Connection::open(&db_path)
.map_err(|e| format!("Failed to open database: {e}"))?;
conn.execute(
"INSERT OR IGNORE INTO sessions (name, description, work_dir) VALUES (?1, ?2, ?3)",
rusqlite::params![name, description, work_dir],
).map_err(|e| format!("Failed to register project: {e}"))?;
Ok(())
}
pub fn list_projects(&self) -> Result<Vec<CtxProject>, String> {
let lock = self.conn.lock().unwrap();
let conn = lock.as_ref().ok_or("ctx database not found")?;

View file

@ -187,6 +187,11 @@ fn ctx_init_db(state: State<'_, AppState>) -> Result<(), String> {
state.ctx_db.init_db()
}
#[tauri::command]
fn ctx_register_project(state: State<'_, AppState>, name: String, description: String, work_dir: Option<String>) -> Result<(), String> {
state.ctx_db.register_project(&name, &description, work_dir.as_deref())
}
#[tauri::command]
fn ctx_list_projects(state: State<'_, AppState>) -> Result<Vec<ctx::CtxProject>, String> {
state.ctx_db.list_projects()
@ -545,6 +550,7 @@ pub fn run() {
ssh_session_save,
ssh_session_delete,
ctx_init_db,
ctx_register_project,
ctx_list_projects,
ctx_get_context,
ctx_get_shared,