Initial settings implementation

This commit is contained in:
Gregory Schier
2024-01-11 21:13:17 -08:00
parent c1c9f882a6
commit 138943bfb6
18 changed files with 426 additions and 65 deletions

View File

@@ -521,6 +521,31 @@ async fn list_environments(
Ok(environments)
}
#[tauri::command]
async fn get_settings(
db_instance: State<'_, Mutex<Pool<Sqlite>>>,
) -> Result<models::Settings, String> {
let pool = &*db_instance.lock().await;
models::get_or_create_settings(pool)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
async fn update_settings(
settings: models::Settings,
window: Window<Wry>,
db_instance: State<'_, Mutex<Pool<Sqlite>>>,
) -> Result<models::Settings, String> {
let pool = &*db_instance.lock().await;
let updated_settings = models::update_settings(pool, settings)
.await
.expect("Failed to update settings");
emit_and_return(&window, "updated_model", updated_settings)
}
#[tauri::command]
async fn get_folder(
id: &str,
@@ -731,6 +756,7 @@ fn main() {
get_environment,
get_folder,
get_request,
get_settings,
get_workspace,
import_data,
list_environments,
@@ -747,6 +773,7 @@ fn main() {
update_environment,
update_folder,
update_request,
update_settings,
update_workspace,
])
.build(tauri::generate_context!())