Skip to content

Commit

Permalink
Make previous changes backwards-compatible
Browse files Browse the repository at this point in the history
Depending on the existence of the original config location, uses it or
the new location

This prevents the backwards-incompatible change at the cost of some
checking on every config query.
  • Loading branch information
LucasFA committed Feb 5, 2024
1 parent 5caa7a1 commit 307dade
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions spotify_player/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod keymap;
mod theme;

const DEFAULT_CONFIG_FOLDER: &str = ".config/spotify-player";
const APP_CONFIG_FILE: &str = "app.toml";
const THEME_CONFIG_FILE: &str = "theme.toml";
const KEYMAP_CONFIG_FILE: &str = "keymap.toml";
Expand Down Expand Up @@ -323,10 +324,17 @@ const APP_NAME: &str = "spotify-player";

/// gets the application's configuration folder path
pub fn get_config_folder_path() -> Result<PathBuf> {
match dirs_next::config_dir() {
Some(config_home) => Ok(config_home.join(APP_NAME)),
None => Err(anyhow!("cannot find the $HOME folder")),
if let Some(home) = dirs_next::home_dir() {
let old_path = home.join(DEFAULT_CONFIG_FOLDER);
if old_path.exists() {
return Ok(old_path);
}
}
if let Some(config_home) = dirs_next::config_dir() {
return Ok(config_home.join(APP_NAME));
}

Err(anyhow!("cannot find the $HOME folder"))
}

/// gets the application's cache folder path
Expand Down

0 comments on commit 307dade

Please sign in to comment.