diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-04-29 14:59:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-29 14:59:59 +0100 |
| commit | cea48a1545250429b78235b2ad00b8243923e2b2 (patch) | |
| tree | 08866c06ee81bf841e6bf0f20feb9a88c9435cfa /ui/backend/src | |
| parent | chore(deps): bump rustix from 0.38.32 to 0.38.34 (#1986) (diff) | |
| download | atuin-cea48a1545250429b78235b2ad00b8243923e2b2.zip | |
feat(ui/dotfiles): add vars (#1989)
Diffstat (limited to 'ui/backend/src')
| -rw-r--r-- | ui/backend/src/dotfiles/mod.rs | 1 | ||||
| -rw-r--r-- | ui/backend/src/dotfiles/vars.rs | 57 | ||||
| -rw-r--r-- | ui/backend/src/main.rs | 3 |
3 files changed, 61 insertions, 0 deletions
diff --git a/ui/backend/src/dotfiles/mod.rs b/ui/backend/src/dotfiles/mod.rs index d293a01b..feafe783 100644 --- a/ui/backend/src/dotfiles/mod.rs +++ b/ui/backend/src/dotfiles/mod.rs @@ -1 +1,2 @@ pub mod aliases; +pub mod vars; diff --git a/ui/backend/src/dotfiles/vars.rs b/ui/backend/src/dotfiles/vars.rs new file mode 100644 index 00000000..d8d5bd75 --- /dev/null +++ b/ui/backend/src/dotfiles/vars.rs @@ -0,0 +1,57 @@ +use std::path::PathBuf; + +use atuin_client::{encryption, record::sqlite_store::SqliteStore, settings::Settings}; +use atuin_common::shell::Shell; +use atuin_dotfiles::{ + shell::{existing_aliases, Alias, Var}, + store::var::VarStore, +}; + +async fn var_store() -> eyre::Result<VarStore> { + let settings = Settings::new()?; + + let record_store_path = PathBuf::from(settings.record_store_path.as_str()); + let sqlite_store = SqliteStore::new(record_store_path, settings.local_timeout).await?; + + let encryption_key: [u8; 32] = encryption::load_key(&settings)?.into(); + + let host_id = Settings::host_id().expect("failed to get host_id"); + + Ok(VarStore::new(sqlite_store, host_id, encryption_key)) +} + +#[tauri::command] +pub async fn vars() -> Result<Vec<Var>, String> { + let var_store = var_store().await.map_err(|e| e.to_string())?; + + let vars = var_store + .vars() + .await + .map_err(|e| format!("failed to load aliases: {}", e))?; + + Ok(vars) +} + +#[tauri::command] +pub async fn delete_var(name: String) -> Result<(), String> { + let var_store = var_store().await.map_err(|e| e.to_string())?; + + var_store + .delete(name.as_str()) + .await + .map_err(|e| e.to_string())?; + + Ok(()) +} + +#[tauri::command] +pub async fn set_var(name: String, value: String, export: bool) -> Result<(), String> { + let var_store = var_store().await.map_err(|e| e.to_string())?; + + var_store + .set(name.as_str(), value.as_str(), export) + .await + .map_err(|e| e.to_string())?; + + Ok(()) +} diff --git a/ui/backend/src/main.rs b/ui/backend/src/main.rs index fbcf9481..fe6271b8 100644 --- a/ui/backend/src/main.rs +++ b/ui/backend/src/main.rs @@ -118,6 +118,9 @@ fn main() { dotfiles::aliases::import_aliases, dotfiles::aliases::delete_alias, dotfiles::aliases::set_alias, + dotfiles::vars::vars, + dotfiles::vars::delete_var, + dotfiles::vars::set_var, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); |
