mirror of
https://github.com/Dangoware/dmp-core.git
synced 2025-04-19 09:42:56 -05:00
Moved config
to a mod.rs
file, made controller Player static
This commit is contained in:
parent
54704260ba
commit
0513109de8
7 changed files with 30 additions and 21 deletions
|
@ -1,3 +1,5 @@
|
|||
pub mod other_settings;
|
||||
|
||||
use std::{
|
||||
fs::{self, File, OpenOptions},
|
||||
io::{Error, Read, Write},
|
||||
|
@ -214,7 +216,7 @@ pub mod tests {
|
|||
)
|
||||
.unwrap();
|
||||
lib.scan_folder("test-config/music/").unwrap();
|
||||
lib.save(config.clone()).unwrap();
|
||||
lib.save(Arc::new(RwLock::new(config.clone()))).unwrap();
|
||||
|
||||
(config, lib)
|
||||
}
|
||||
|
@ -232,7 +234,7 @@ pub mod tests {
|
|||
|
||||
lib.scan_folder("test-config/music/").unwrap();
|
||||
|
||||
lib.save(config.clone()).unwrap();
|
||||
lib.save(Arc::new(RwLock::new(config.clone()))).unwrap();
|
||||
|
||||
(config, lib)
|
||||
}
|
|
@ -18,8 +18,5 @@ pub mod music_player {
|
|||
pub mod gstreamer;
|
||||
pub mod player;
|
||||
}
|
||||
#[allow(clippy::module_inception)]
|
||||
pub mod config {
|
||||
pub mod config;
|
||||
pub mod other_settings;
|
||||
}
|
||||
|
||||
pub mod config;
|
||||
|
|
|
@ -13,10 +13,10 @@ use crossbeam_channel::unbounded;
|
|||
use std::error::Error;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::config::config::ConfigError;
|
||||
use crate::config::ConfigError;
|
||||
use crate::music_player::player::{Player, PlayerCommand, PlayerError};
|
||||
use crate::{
|
||||
config::config::Config, music_controller::queue::Queue, music_storage::library::MusicLibrary,
|
||||
config::Config, music_controller::queue::Queue, music_storage::library::MusicLibrary,
|
||||
};
|
||||
|
||||
use super::queue::QueueError;
|
||||
|
@ -25,7 +25,7 @@ pub struct Controller<P: Player + Send + Sync> {
|
|||
pub queue: Queue,
|
||||
pub config: Arc<RwLock<Config>>,
|
||||
pub library: MusicLibrary,
|
||||
pub player: Arc<RwLock<Box<P>>>,
|
||||
pub player: Arc<RwLock<P>>,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
|
@ -70,7 +70,7 @@ impl<T: Send, U: Send> MailMan<T, U> {
|
|||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
impl<P: Player + Send + Sync> Controller<P> {
|
||||
impl<P: Player + Send + Sync + Sized + 'static> Controller<P> {
|
||||
pub fn start<T>(config_path: T) -> Result<Self, Box<dyn Error>>
|
||||
where
|
||||
std::path::PathBuf: std::convert::From<T>,
|
||||
|
@ -88,12 +88,11 @@ impl<P: Player + Send + Sync> Controller<P> {
|
|||
queue: Queue::default(),
|
||||
config: config_.clone(),
|
||||
library,
|
||||
player: Arc::new(RwLock::new(Box::new(P::new()?))),
|
||||
player: Arc::new(RwLock::new(P::new()?)),
|
||||
};
|
||||
|
||||
|
||||
let player = controller.player.clone();
|
||||
let controler_thread = spawn(move || {
|
||||
let player = Arc::clone(&controller.player);
|
||||
let controller_thread = spawn(move || {
|
||||
match player.read().unwrap().message_channel().recv().unwrap() {
|
||||
PlayerCommand::AboutToFinish => {},
|
||||
PlayerCommand::EndOfStream => {
|
||||
|
@ -115,4 +114,15 @@ impl<P: Player + Send + Sync> Controller<P> {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_super {}
|
||||
mod test_super {
|
||||
use crate::{config::tests::read_config_lib, music_player::gstreamer::GStreamer};
|
||||
|
||||
use super::Controller;
|
||||
|
||||
#[test]
|
||||
fn construct_controller() {
|
||||
let config = read_config_lib();
|
||||
|
||||
let controller = Controller::<GStreamer>::start("test-config/config_test.json").unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -391,7 +391,7 @@ impl Queue {
|
|||
mod test_super {
|
||||
#![allow(unused)]
|
||||
use crate::{
|
||||
config::config::tests::{new_config_lib, read_config_lib},
|
||||
config::tests::{new_config_lib, read_config_lib},
|
||||
music_storage::library,
|
||||
};
|
||||
|
||||
|
|
|
@ -336,7 +336,7 @@ impl ITunesSong {
|
|||
mod tests {
|
||||
use std::{path::{Path, PathBuf}, sync::{Arc, RwLock}};
|
||||
|
||||
use crate::{config::config::{Config, ConfigLibrary}, music_storage::{db_reader::extern_library::ExternalLibrary, library::MusicLibrary}};
|
||||
use crate::{config::{Config, ConfigLibrary}, music_storage::{db_reader::extern_library::ExternalLibrary, library::MusicLibrary}};
|
||||
|
||||
use super::ITunesLibrary;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use super::playlist::PlaylistFolder;
|
||||
// Crate things
|
||||
use super::utils::{find_images, normalize, read_file, write_file};
|
||||
use crate::config::config::Config;
|
||||
use crate::config::Config;
|
||||
|
||||
// Various std things
|
||||
use std::collections::BTreeMap;
|
||||
|
@ -1127,7 +1127,7 @@ mod test {
|
|||
sync::{Arc, RwLock},
|
||||
};
|
||||
|
||||
use crate::{config::config::Config, music_storage::library::MusicLibrary};
|
||||
use crate::{config::{tests::new_config_lib, Config}, music_storage::library::MusicLibrary};
|
||||
|
||||
#[test]
|
||||
fn library_init() {
|
||||
|
|
|
@ -315,7 +315,7 @@ impl Default for Playlist {
|
|||
#[cfg(test)]
|
||||
mod test_super {
|
||||
use super::*;
|
||||
use crate::config::config::tests::read_config_lib;
|
||||
use crate::config::tests::read_config_lib;
|
||||
|
||||
#[test]
|
||||
fn list_to_m3u8() {
|
||||
|
|
Loading…
Reference in a new issue