streamd/src/config.rs
Konstantin Fickel 822d9194ae fix: cross-platform compatibility for Windows support
- Use directories::BaseDirs for config path fallback instead of hardcoded Unix path
- Default to notepad on Windows instead of vi for editor commands
- Skip +N line argument for notepad in todo edit (notepad doesn't support it)
2026-04-13 19:38:15 +02:00

46 lines
1.2 KiB
Rust

use directories::ProjectDirs;
use serde::{Deserialize, Serialize};
use std::env;
use std::fs;
use std::path::PathBuf;
use crate::error::StreamdError;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Settings {
pub base_folder: String,
}
impl Default for Settings {
fn default() -> Self {
Self {
base_folder: env::current_dir()
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_else(|_| ".".to_string()),
}
}
}
impl Settings {
pub fn load() -> Result<Self, StreamdError> {
let config_path = Self::config_path();
if config_path.exists() {
let content = fs::read_to_string(&config_path)?;
let settings: Settings = toml::from_str(&content)?;
Ok(settings)
} else {
Ok(Settings::default())
}
}
fn config_path() -> PathBuf {
if let Some(proj_dirs) = ProjectDirs::from("", "", "streamd") {
proj_dirs.config_dir().join("config.toml")
} else if let Some(base_dirs) = directories::BaseDirs::new() {
base_dirs.config_dir().join("streamd").join("config.toml")
} else {
PathBuf::from("streamd_config.toml")
}
}
}