mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 10:02:53 -05:00
removed config passing in library functions
This commit is contained in:
parent
e97075401d
commit
be9f28e38f
5 changed files with 11 additions and 17 deletions
|
@ -211,12 +211,12 @@ pub mod tests {
|
||||||
config.write_file().unwrap();
|
config.write_file().unwrap();
|
||||||
|
|
||||||
let mut lib = MusicLibrary::init(
|
let mut lib = MusicLibrary::init(
|
||||||
Arc::new(RwLock::from(config.clone())),
|
config.libraries.get_default().unwrap().path.clone(),
|
||||||
dbg!(config.libraries.default_library),
|
dbg!(config.libraries.default_library),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
lib.scan_folder("test-config/music/").unwrap();
|
lib.scan_folder("test-config/music/").unwrap();
|
||||||
lib.save(Arc::new(RwLock::new(config.clone()))).unwrap();
|
lib.save(config.libraries.get_default().unwrap().path.clone()).unwrap();
|
||||||
|
|
||||||
(config, lib)
|
(config, lib)
|
||||||
}
|
}
|
||||||
|
@ -227,14 +227,14 @@ pub mod tests {
|
||||||
// dbg!(&config);
|
// dbg!(&config);
|
||||||
|
|
||||||
let mut lib = MusicLibrary::init(
|
let mut lib = MusicLibrary::init(
|
||||||
Arc::new(RwLock::from(config.clone())),
|
config.libraries.get_default().unwrap().path.clone(),
|
||||||
config.libraries.get_default().unwrap().uuid,
|
config.libraries.get_default().unwrap().uuid,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
lib.scan_folder("test-config/music/").unwrap();
|
lib.scan_folder("test-config/music/").unwrap();
|
||||||
|
|
||||||
lib.save(Arc::new(RwLock::new(config.clone()))).unwrap();
|
lib.save(config.libraries.get_default().unwrap().path.clone()).unwrap();
|
||||||
|
|
||||||
(config, lib)
|
(config, lib)
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,8 +95,9 @@ impl<P: Player + Send + Sync + Sized + 'static> Controller<P> {
|
||||||
let config = Config::read_file(config_path)?;
|
let config = Config::read_file(config_path)?;
|
||||||
let uuid = config.libraries.get_default()?.uuid;
|
let uuid = config.libraries.get_default()?.uuid;
|
||||||
|
|
||||||
|
let library = MusicLibrary::init(config.libraries.get_default()?.path.clone(), uuid)?;
|
||||||
let config_ = Arc::new(RwLock::from(config));
|
let config_ = Arc::new(RwLock::from(config));
|
||||||
let library = MusicLibrary::init(config_.clone(), uuid)?;
|
|
||||||
|
|
||||||
let queue: Queue<QueueSong, QueueAlbum> = Queue {
|
let queue: Queue<QueueSong, QueueAlbum> = Queue {
|
||||||
items: Vec::new(),
|
items: Vec::new(),
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
// Crate things
|
// Crate things
|
||||||
//use crate::music_controller::config::Config;
|
|
||||||
use crate::music_storage::library::URI;
|
use crate::music_storage::library::URI;
|
||||||
use crossbeam_channel::{unbounded, Receiver, Sender};
|
use crossbeam_channel::{unbounded, Receiver, Sender};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
|
@ -348,11 +348,11 @@ mod tests {
|
||||||
|
|
||||||
let songs = ITunesLibrary::from_file(Path::new("test-config\\iTunesLib.xml")).to_songs();
|
let songs = ITunesLibrary::from_file(Path::new("test-config\\iTunesLib.xml")).to_songs();
|
||||||
|
|
||||||
let mut library = MusicLibrary::init(Arc::new(RwLock::from(config.clone())), config_lib.uuid).unwrap();
|
let mut library = MusicLibrary::init(config.libraries.get_default().unwrap().path.clone(), config_lib.uuid).unwrap();
|
||||||
|
|
||||||
songs.iter().for_each(|song| library.add_song(song.to_owned()).unwrap());
|
songs.iter().for_each(|song| library.add_song(song.to_owned()).unwrap());
|
||||||
|
|
||||||
config.write_file().unwrap();
|
config.write_file().unwrap();
|
||||||
library.save(Arc::new(RwLock::from(config))).unwrap();
|
library.save(config.libraries.get_default().unwrap().path.clone()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -699,21 +699,16 @@ impl MusicLibrary {
|
||||||
/// If the database file already exists, return the [MusicLibrary], otherwise create
|
/// If the database file already exists, return the [MusicLibrary], otherwise create
|
||||||
/// the database first. This needs to be run before anything else to retrieve
|
/// the database first. This needs to be run before anything else to retrieve
|
||||||
/// the [MusicLibrary] Vec
|
/// the [MusicLibrary] Vec
|
||||||
pub fn init(config: Arc<RwLock<Config>>, uuid: Uuid) -> Result<Self, Box<dyn Error>> {
|
pub fn init(path: PathBuf, uuid: Uuid) -> Result<Self, Box<dyn Error>> {
|
||||||
let global_config = &*config.read().unwrap();
|
|
||||||
let path = global_config.libraries.get_library(&uuid)?.path.clone();
|
|
||||||
|
|
||||||
let library: MusicLibrary = match path.exists() {
|
let library: MusicLibrary = match path.exists() {
|
||||||
true => read_file(path)?,
|
true => read_file(path)?,
|
||||||
false => {
|
false => {
|
||||||
// If the library does not exist, re-create it
|
// If the library does not exist, re-create it
|
||||||
let lib = MusicLibrary::new(String::new(), uuid);
|
let lib = MusicLibrary::new(String::new(), uuid);
|
||||||
|
|
||||||
write_file(&lib, path)?;
|
write_file(&lib, path)?;
|
||||||
lib
|
lib
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(library)
|
Ok(library)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,8 +738,7 @@ impl MusicLibrary {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serializes the database out to the file specified in the config
|
/// Serializes the database out to the file specified in the config
|
||||||
pub fn save(&self, config: Arc<RwLock<Config>>) -> Result<(), Box<dyn Error>> {
|
pub fn save(&self, path: PathBuf) -> Result<(), Box<dyn Error>> {
|
||||||
let path = config.read().unwrap().libraries.get_library(&self.uuid)?.path.clone();
|
|
||||||
match path.try_exists() {
|
match path.try_exists() {
|
||||||
Ok(_) => write_file(self, path)?,
|
Ok(_) => write_file(self, path)?,
|
||||||
Err(error) => return Err(error.into()),
|
Err(error) => return Err(error.into()),
|
||||||
|
@ -1229,7 +1223,7 @@ mod test {
|
||||||
fn library_init() {
|
fn library_init() {
|
||||||
let config = Config::read_file(PathBuf::from("test_config/config_test.json")).unwrap();
|
let config = Config::read_file(PathBuf::from("test_config/config_test.json")).unwrap();
|
||||||
let target_uuid = config.libraries.libraries[0].uuid;
|
let target_uuid = config.libraries.libraries[0].uuid;
|
||||||
let a = MusicLibrary::init(Arc::new(RwLock::from(config)), target_uuid).unwrap();
|
let a = MusicLibrary::init(config.libraries.get_default().unwrap().path.clone(), target_uuid).unwrap();
|
||||||
dbg!(a);
|
dbg!(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue