From 307dadeb656cc232686c90cdf115894f89d8218a Mon Sep 17 00:00:00 2001 From: LucasFA <23667494+LucasFA@users.noreply.github.com> Date: Mon, 5 Feb 2024 23:32:52 +0100 Subject: [PATCH] Make previous changes backwards-compatible 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. --- spotify_player/src/config/mod.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spotify_player/src/config/mod.rs b/spotify_player/src/config/mod.rs index ba471a6b..69fe2159 100644 --- a/spotify_player/src/config/mod.rs +++ b/spotify_player/src/config/mod.rs @@ -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"; @@ -323,10 +324,17 @@ const APP_NAME: &str = "spotify-player"; /// gets the application's configuration folder path pub fn get_config_folder_path() -> Result { - 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