diff options
Diffstat (limited to '')
| -rw-r--r-- | src/config.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/config.rs b/src/config.rs index cda59f4..42573ed 100644 --- a/src/config.rs +++ b/src/config.rs | |||
| @@ -20,13 +20,19 @@ pub struct Config { | |||
| 20 | 20 | ||
| 21 | impl Config { | 21 | impl Config { |
| 22 | pub fn load() -> Result<Self, Box<dyn std::error::Error>> { | 22 | pub fn load() -> Result<Self, Box<dyn std::error::Error>> { |
| 23 | let proj_dirs = ProjectDirs::from("com", "rsplayer", "rsplayer") | 23 | let config_dir = if cfg!(debug_assertions) { |
| 24 | .ok_or("Failed to get project directories")?; | 24 | std::env::current_exe()? |
| 25 | 25 | .parent() | |
| 26 | let config_dir = if let Ok(xdg) = std::env::var("XDG_CONFIG_HOME") { | 26 | .map(|p| p.to_path_buf()) |
| 27 | PathBuf::from(xdg).join("rsplayer") | 27 | .unwrap_or_else(|| PathBuf::from(".")) |
| 28 | } else { | 28 | } else { |
| 29 | proj_dirs.config_dir().to_path_buf() | 29 | let proj_dirs = ProjectDirs::from("com", "rsplayer", "rsplayer") |
| 30 | .ok_or("Failed to get project directories")?; | ||
| 31 | if let Ok(xdg) = std::env::var("XDG_CONFIG_HOME") { | ||
| 32 | PathBuf::from(xdg).join("rsplayer") | ||
| 33 | } else { | ||
| 34 | proj_dirs.config_dir().to_path_buf() | ||
| 35 | } | ||
| 30 | }; | 36 | }; |
| 31 | 37 | ||
| 32 | let config_path = config_dir.join("config.toml"); | 38 | let config_path = config_dir.join("config.toml"); |
