Skip to main content

max / balanced_breakfast

803 B · 32 lines History Blame Raw
1 //! User config commands (synced key-value preferences)
2 use crate::commands::error::ApiError;
3 use crate::state::AppState;
4 use std::sync::Arc;
5 use tauri::State;
6 use tracing::instrument;
7
8 /// Get a user config value by key.
9 #[tauri::command]
10 #[instrument(skip_all)]
11 pub async fn get_config(
12 state: State<'_, Arc<AppState>>,
13 key: String,
14 ) -> Result<Option<String>, ApiError> {
15 let db = state.orchestrator.database();
16 let value = db.config().get(&key).await?;
17 Ok(value)
18 }
19
20 /// Set a user config value (upserts on key).
21 #[tauri::command]
22 #[instrument(skip_all)]
23 pub async fn set_config(
24 state: State<'_, Arc<AppState>>,
25 key: String,
26 value: String,
27 ) -> Result<(), ApiError> {
28 let db = state.orchestrator.database();
29 db.config().set(&key, &value).await?;
30 Ok(())
31 }
32