feat: config vaults desktop — VaultConfig, add_vault, remove_vault, list_vaults
CI / lint (push) Successful in 24s
CI / security (push) Successful in 13s
CI / test (push) Successful in 29s
CI / build (push) Successful in 12s
CI / e2e (push) Failing after 14s
Desktop Build / build-windows (push) Has been cancelled
Desktop Build / build-linux (push) Has been cancelled
CI / lint (push) Successful in 24s
CI / security (push) Successful in 13s
CI / test (push) Successful in 29s
CI / build (push) Successful in 12s
CI / e2e (push) Failing after 14s
Desktop Build / build-windows (push) Has been cancelled
Desktop Build / build-linux (push) Has been cancelled
- AppConfig: nouveau champ vaults: Vec<VaultConfig> (name + path) - spawn_backend: passe VAULT_N_NAME / VAULT_N_PATH en variables d'env - Commandes Tauri: add_vault, remove_vault, list_vaults - Nécessite restart_backend() pour appliquer les changements
This commit is contained in:
+49
-3
@@ -16,9 +16,16 @@ struct BackendProcess {
|
|||||||
restarting: Mutex<bool>,
|
restarting: Mutex<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
struct VaultConfig {
|
||||||
|
name: String,
|
||||||
|
path: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
struct AppConfig {
|
struct AppConfig {
|
||||||
vault_path: Option<String>,
|
vault_path: Option<String>,
|
||||||
|
vaults: Vec<VaultConfig>,
|
||||||
window_x: Option<f64>,
|
window_x: Option<f64>,
|
||||||
window_y: Option<f64>,
|
window_y: Option<f64>,
|
||||||
window_width: Option<f64>,
|
window_width: Option<f64>,
|
||||||
@@ -29,6 +36,7 @@ impl Default for AppConfig {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
vault_path: None,
|
vault_path: None,
|
||||||
|
vaults: Vec::new(),
|
||||||
window_x: None,
|
window_x: None,
|
||||||
window_y: None,
|
window_y: None,
|
||||||
window_width: Some(1200.0),
|
window_width: Some(1200.0),
|
||||||
@@ -123,9 +131,19 @@ fn spawn_backend(exe_dir: &PathBuf) -> Result<Child, String> {
|
|||||||
let data_dir = app_data_dir();
|
let data_dir = app_data_dir();
|
||||||
let _ = fs::create_dir_all(data_dir.join("data"));
|
let _ = fs::create_dir_all(data_dir.join("data"));
|
||||||
|
|
||||||
let child = Command::new(&python)
|
let mut cmd = Command::new(&python);
|
||||||
.current_dir(&data_dir)
|
cmd.current_dir(&data_dir)
|
||||||
.env("PYTHONPATH", exe_dir)
|
.env("PYTHONPATH", exe_dir);
|
||||||
|
|
||||||
|
// Pass vault config as env vars (VAULT_1_NAME, VAULT_1_PATH, etc.)
|
||||||
|
let config = load_config();
|
||||||
|
for (i, vault) in config.vaults.iter().enumerate() {
|
||||||
|
let n = i + 1;
|
||||||
|
cmd.env(format!("VAULT_{}_NAME", n), &vault.name);
|
||||||
|
cmd.env(format!("VAULT_{}_PATH", n), &vault.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let child = cmd
|
||||||
.args([
|
.args([
|
||||||
"-m", "uvicorn",
|
"-m", "uvicorn",
|
||||||
"backend.main:app",
|
"backend.main:app",
|
||||||
@@ -235,6 +253,31 @@ fn get_system_theme(app: tauri::AppHandle) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn add_vault(name: String, path: String) -> Result<(), String> {
|
||||||
|
let mut config = load_config();
|
||||||
|
// Avoid duplicates
|
||||||
|
config.vaults.retain(|v| v.name != name);
|
||||||
|
config.vaults.push(VaultConfig { name: name.clone(), path });
|
||||||
|
save_config(&config);
|
||||||
|
info!("Vault added: {} — restart backend to apply", name);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn remove_vault(name: String) -> Result<(), String> {
|
||||||
|
let mut config = load_config();
|
||||||
|
config.vaults.retain(|v| v.name != name);
|
||||||
|
save_config(&config);
|
||||||
|
info!("Vault removed: {} — restart backend to apply", name);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn list_vaults() -> Vec<VaultConfig> {
|
||||||
|
load_config().vaults
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn restart_backend(state: tauri::State<BackendProcess>) -> Result<String, String> {
|
fn restart_backend(state: tauri::State<BackendProcess>) -> Result<String, String> {
|
||||||
let mut restarting = state.restarting.lock().map_err(|e| e.to_string())?;
|
let mut restarting = state.restarting.lock().map_err(|e| e.to_string())?;
|
||||||
@@ -393,6 +436,9 @@ fn main() {
|
|||||||
check_backend_health,
|
check_backend_health,
|
||||||
save_window_state,
|
save_window_state,
|
||||||
get_window_state,
|
get_window_state,
|
||||||
|
add_vault,
|
||||||
|
remove_vault,
|
||||||
|
list_vaults,
|
||||||
])
|
])
|
||||||
.setup(move |app| {
|
.setup(move |app| {
|
||||||
// Restore window position/size
|
// Restore window position/size
|
||||||
|
|||||||
Reference in New Issue
Block a user