Put in a recent project picker
This commit is contained in:
@@ -7,6 +7,7 @@ use std::path::PathBuf;
|
||||
|
||||
const KEY_LAST_PROJECT: &str = "last_project_path";
|
||||
const KEY_SELECTED_MODEL: &str = "selected_model";
|
||||
const KEY_KNOWN_PROJECTS: &str = "known_projects";
|
||||
|
||||
/// Resolves a relative path against the active project root (pure function for testing).
|
||||
/// Returns error if path attempts traversal (..).
|
||||
@@ -55,6 +56,13 @@ pub async fn open_project(
|
||||
}
|
||||
|
||||
store.set(KEY_LAST_PROJECT, json!(path));
|
||||
|
||||
let mut known_projects = get_known_projects(store)?;
|
||||
|
||||
known_projects.retain(|p| p != &path);
|
||||
known_projects.insert(0, path.clone());
|
||||
store.set(KEY_KNOWN_PROJECTS, json!(known_projects));
|
||||
|
||||
store.save()?;
|
||||
|
||||
Ok(path)
|
||||
@@ -99,6 +107,18 @@ pub fn get_current_project(
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub fn get_known_projects(store: &dyn StoreOps) -> Result<Vec<String>, String> {
|
||||
let projects = store
|
||||
.get(KEY_KNOWN_PROJECTS)
|
||||
.and_then(|val| val.as_array().cloned())
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.filter_map(|val| val.as_str().map(|s| s.to_string()))
|
||||
.collect();
|
||||
|
||||
Ok(projects)
|
||||
}
|
||||
|
||||
pub fn get_model_preference(store: &dyn StoreOps) -> Result<Option<String>, String> {
|
||||
if let Some(model) = store
|
||||
.get(KEY_SELECTED_MODEL)
|
||||
|
||||
Reference in New Issue
Block a user