Reopen the last project with a focused draft chat

This commit is contained in:
Georg Bauer
2026-07-25 23:52:39 +02:00
parent 4408ed8b26
commit e44680541d
8 changed files with 71 additions and 13 deletions

View File

@@ -55,6 +55,8 @@ pub struct AppPreferences {
pub endpoint_enabled: bool,
pub endpoint_cors: bool,
pub sidebar_collapsed: bool,
/// Project the app reopens on. Cleared when that project goes away.
pub last_project_id: Option<i32>,
}
impl Default for AppPreferences {
@@ -98,6 +100,7 @@ impl Default for AppPreferences {
endpoint_enabled: true,
endpoint_cors: false,
sidebar_collapsed: false,
last_project_id: None,
}
}
}
@@ -441,6 +444,14 @@ impl Database {
.map_err(|error| error.to_string())
}
pub fn set_last_project(&mut self, project_id: Option<i32>) -> Result<(), String> {
diesel::update(preferences::table.find(1))
.set(preferences::last_project_id.eq(project_id))
.execute(&mut self.connection)
.map(|_| ())
.map_err(|error| error.to_string())
}
#[allow(clippy::too_many_arguments)]
pub fn update_preferences(
&mut self,
@@ -851,6 +862,7 @@ mod tests {
assert_eq!(loaded[0].sessions[0].id, ordinary);
database.set_sidebar_collapsed(true).unwrap();
database.set_last_project(Some(project.id)).unwrap();
database.delete_project(project.id).unwrap();
assert!(database.load_projects().unwrap().is_empty());
@@ -859,6 +871,7 @@ mod tests {
let mut reopened = Database::open(&path).unwrap();
let preferences = reopened.load_preferences().unwrap();
assert!(preferences.sidebar_collapsed);
assert_eq!(preferences.last_project_id, Some(project.id));
assert_eq!(preferences.selected_model, "glm-5.2");
assert_eq!(preferences.idle_timeout_minutes, 30);
assert_eq!(preferences.endpoint_port, 4567);