feat: follow XDG spec on linux/mac and use windows known folders for config and logs (#1153)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use etcetera::{choose_app_strategy, AppStrategy, AppStrategyArgs};
|
||||
use keyring::Entry;
|
||||
use once_cell::sync::OnceCell;
|
||||
use once_cell::sync::{Lazy, OnceCell};
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
@@ -7,6 +8,12 @@ use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use thiserror::Error;
|
||||
|
||||
pub static APP_STRATEGY: Lazy<AppStrategyArgs> = Lazy::new(|| AppStrategyArgs {
|
||||
top_level_domain: "Block".to_string(),
|
||||
author: "Block".to_string(),
|
||||
app_name: "goose".to_string(),
|
||||
});
|
||||
|
||||
const KEYRING_SERVICE: &str = "goose";
|
||||
const KEYRING_USERNAME: &str = "secrets";
|
||||
|
||||
@@ -99,10 +106,13 @@ static GLOBAL_CONFIG: OnceCell<Config> = OnceCell::new();
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
let config_dir = dirs::home_dir()
|
||||
// choose_app_strategy().config_dir()
|
||||
// - macOS/Linux: ~/.config/goose/
|
||||
// - Windows: ~\AppData\Roaming\Block\goose\config\
|
||||
let config_dir = choose_app_strategy(APP_STRATEGY.clone())
|
||||
.expect("goose requires a home dir")
|
||||
.join(".config")
|
||||
.join("goose");
|
||||
.config_dir();
|
||||
|
||||
std::fs::create_dir_all(&config_dir).expect("Failed to create config directory");
|
||||
|
||||
let config_path = config_dir.join("config.yaml");
|
||||
|
||||
@@ -2,5 +2,5 @@ mod base;
|
||||
mod extensions;
|
||||
|
||||
pub use crate::agents::ExtensionConfig;
|
||||
pub use base::{Config, ConfigError};
|
||||
pub use base::{Config, ConfigError, APP_STRATEGY};
|
||||
pub use extensions::{ExtensionEntry, ExtensionManager};
|
||||
|
||||
Reference in New Issue
Block a user