Skip to content

Commit 8142a11

Browse files
sinelawclaude
andcommitted
Load config from default location on app startup
Previously, when no --config flag was provided, the app would use Config::default() which ignores any saved user preferences in ~/.config/fresh/config.json. Now it uses Config::load_or_default() which tries to load from the default config location first, falling back to defaults only if the file doesn't exist or fails to parse. This fixes the issue where theme selection (and other config changes) weren't persisted across app restarts. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent aa2007b commit 8142a11

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/config.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,30 @@ impl Default for MenuConfig {
382382
}
383383

384384
impl Config {
385+
/// Get the default config file path
386+
pub fn default_config_path() -> Option<std::path::PathBuf> {
387+
dirs::config_dir().map(|d| d.join("fresh").join("config.json"))
388+
}
389+
390+
/// Load configuration from the default location, falling back to defaults if not found
391+
pub fn load_or_default() -> Self {
392+
if let Some(config_path) = Self::default_config_path() {
393+
if config_path.exists() {
394+
match Self::load_from_file(&config_path) {
395+
Ok(config) => return config,
396+
Err(e) => {
397+
tracing::warn!(
398+
"Failed to load config from {}: {}, using defaults",
399+
config_path.display(),
400+
e
401+
);
402+
}
403+
}
404+
}
405+
}
406+
Self::default()
407+
}
408+
385409
/// Load configuration from a JSON file
386410
pub fn load_from_file<P: AsRef<Path>>(path: P) -> Result<Self, ConfigError> {
387411
let contents = std::fs::read_to_string(path.as_ref())

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ fn main() -> io::Result<()> {
127127
}
128128
}
129129
} else {
130-
config::Config::default()
130+
// Try to load from default location, fall back to defaults
131+
config::Config::load_or_default()
131132
};
132133

133134
// Set up terminal first

0 commit comments

Comments
 (0)