refactor for more generic usage of config path helpers
This commit is contained in:
@@ -38,7 +38,7 @@ fn proj_dirs () -> ProjectDirs {
|
||||
ProjectDirs::from("org", "affekt", "ncspot").expect("can't determine project paths")
|
||||
}
|
||||
|
||||
pub fn config_path() -> PathBuf {
|
||||
pub fn config_path(file: &str) -> PathBuf {
|
||||
let proj_dirs = proj_dirs();
|
||||
let cfg_dir = proj_dirs.config_dir();
|
||||
trace!("{:?}", cfg_dir);
|
||||
@@ -46,17 +46,17 @@ pub fn config_path() -> PathBuf {
|
||||
fs::create_dir(cfg_dir).expect("can't create config folder");
|
||||
}
|
||||
let mut cfg = cfg_dir.to_path_buf();
|
||||
cfg.push("config.toml");
|
||||
cfg.push(file);
|
||||
cfg
|
||||
}
|
||||
|
||||
pub fn cache_path() -> PathBuf {
|
||||
pub fn cache_path(file: &str) -> PathBuf {
|
||||
let proj_dirs = proj_dirs();
|
||||
let cache_dir = proj_dirs.cache_dir();
|
||||
if !cache_dir.exists() {
|
||||
fs::create_dir(cache_dir).expect("can't create cache folder");
|
||||
}
|
||||
let mut pb = cache_dir.to_path_buf();
|
||||
pb.push("playlists.db");
|
||||
pb.push(file);
|
||||
pb
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ fn main() {
|
||||
|
||||
// Things here may cause the process to abort; we must do them before creating curses windows
|
||||
// otherwise the error message will not be seen by a user
|
||||
let path = config::config_path();
|
||||
let path = config::config_path("config.toml");
|
||||
|
||||
let cfg: config::Config = {
|
||||
let contents = std::fs::read_to_string(&path).unwrap_or_else(|_| {
|
||||
|
||||
@@ -12,6 +12,8 @@ use spotify::Spotify;
|
||||
use track::Track;
|
||||
use traits::ListItem;
|
||||
|
||||
const CACHE_FILE: &str = "playlists.db";
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Playlist {
|
||||
pub meta: SimplifiedPlaylist,
|
||||
@@ -54,7 +56,7 @@ impl Playlists {
|
||||
store: Arc::new(RwLock::new(Vec::new())),
|
||||
ev: ev.clone(),
|
||||
spotify: spotify.clone(),
|
||||
cache_path: config::cache_path(),
|
||||
cache_path: config::cache_path(CACHE_FILE),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user