feat: persist model selection

This commit is contained in:
Dave
2025-12-25 13:21:55 +00:00
parent a924de8b36
commit d3fa8d940b
4 changed files with 56 additions and 24 deletions

View File

@@ -8,6 +8,7 @@ use tauri_plugin_store::StoreExt;
const STORE_PATH: &str = "store.json";
const KEY_LAST_PROJECT: &str = "last_project_path";
const KEY_SELECTED_MODEL: &str = "selected_model";
// -----------------------------------------------------------------------------
// Helper Functions
@@ -125,6 +126,31 @@ pub async fn get_current_project(
Ok(None)
}
#[tauri::command]
pub async fn get_model_preference(app: AppHandle) -> Result<Option<String>, String> {
let store = app
.store(STORE_PATH)
.map_err(|e| format!("Failed to access store: {}", e))?;
if let Some(val) = store.get(KEY_SELECTED_MODEL) {
if let Some(model) = val.as_str() {
return Ok(Some(model.to_string()));
}
}
Ok(None)
}
#[tauri::command]
pub async fn set_model_preference(app: AppHandle, model: String) -> Result<(), String> {
let store = app
.store(STORE_PATH)
.map_err(|e| format!("Failed to access store: {}", e))?;
store.set(KEY_SELECTED_MODEL, json!(model));
let _ = store.save();
Ok(())
}
#[tauri::command]
pub async fn read_file(path: String, state: State<'_, SessionState>) -> Result<String, String> {
let full_path = resolve_path(&state, &path)?;

View File

@@ -15,6 +15,8 @@ pub fn run() {
commands::fs::open_project,
commands::fs::close_project,
commands::fs::get_current_project,
commands::fs::get_model_preference,
commands::fs::set_model_preference,
commands::fs::read_file,
commands::fs::write_file,
commands::fs::list_directory,