mirror of
https://github.com/Dangoware/dmp-core.git
synced 2025-04-19 13:32:53 -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::{
|
use std::{
|
||||||
fs::{self, File, OpenOptions},
|
fs::{self, File, OpenOptions},
|
||||||
io::{Error, Read, Write},
|
io::{Error, Read, Write},
|
||||||
|
@ -214,7 +216,7 @@ pub mod tests {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
lib.scan_folder("test-config/music/").unwrap();
|
lib.scan_folder("test-config/music/").unwrap();
|
||||||
lib.save(config.clone()).unwrap();
|
lib.save(Arc::new(RwLock::new(config.clone()))).unwrap();
|
||||||
|
|
||||||
(config, lib)
|
(config, lib)
|
||||||
}
|
}
|
||||||
|
@ -232,7 +234,7 @@ pub mod tests {
|
||||||
|
|
||||||
lib.scan_folder("test-config/music/").unwrap();
|
lib.scan_folder("test-config/music/").unwrap();
|
||||||
|
|
||||||
lib.save(config.clone()).unwrap();
|
lib.save(Arc::new(RwLock::new(config.clone()))).unwrap();
|
||||||
|
|
||||||
(config, lib)
|
(config, lib)
|
||||||
}
|
}
|
|
@ -18,8 +18,5 @@ pub mod music_player {
|
||||||
pub mod gstreamer;
|
pub mod gstreamer;
|
||||||
pub mod player;
|
pub mod player;
|
||||||
}
|
}
|
||||||
#[allow(clippy::module_inception)]
|
|
||||||
pub mod config {
|
pub mod config;
|
||||||
pub mod config;
|
|
||||||
pub mod other_settings;
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,10 +13,10 @@ use crossbeam_channel::unbounded;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::config::config::ConfigError;
|
use crate::config::ConfigError;
|
||||||
use crate::music_player::player::{Player, PlayerCommand, PlayerError};
|
use crate::music_player::player::{Player, PlayerCommand, PlayerError};
|
||||||
use crate::{
|
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;
|
use super::queue::QueueError;
|
||||||
|
@ -25,7 +25,7 @@ pub struct Controller<P: Player + Send + Sync> {
|
||||||
pub queue: Queue,
|
pub queue: Queue,
|
||||||
pub config: Arc<RwLock<Config>>,
|
pub config: Arc<RwLock<Config>>,
|
||||||
pub library: MusicLibrary,
|
pub library: MusicLibrary,
|
||||||
pub player: Arc<RwLock<Box<P>>>,
|
pub player: Arc<RwLock<P>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
@ -70,7 +70,7 @@ impl<T: Send, U: Send> MailMan<T, U> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[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>>
|
pub fn start<T>(config_path: T) -> Result<Self, Box<dyn Error>>
|
||||||
where
|
where
|
||||||
std::path::PathBuf: std::convert::From<T>,
|
std::path::PathBuf: std::convert::From<T>,
|
||||||
|
@ -88,12 +88,11 @@ impl<P: Player + Send + Sync> Controller<P> {
|
||||||
queue: Queue::default(),
|
queue: Queue::default(),
|
||||||
config: config_.clone(),
|
config: config_.clone(),
|
||||||
library,
|
library,
|
||||||
player: Arc::new(RwLock::new(Box::new(P::new()?))),
|
player: Arc::new(RwLock::new(P::new()?)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let player = Arc::clone(&controller.player);
|
||||||
let player = controller.player.clone();
|
let controller_thread = spawn(move || {
|
||||||
let controler_thread = spawn(move || {
|
|
||||||
match player.read().unwrap().message_channel().recv().unwrap() {
|
match player.read().unwrap().message_channel().recv().unwrap() {
|
||||||
PlayerCommand::AboutToFinish => {},
|
PlayerCommand::AboutToFinish => {},
|
||||||
PlayerCommand::EndOfStream => {
|
PlayerCommand::EndOfStream => {
|
||||||
|
@ -115,4 +114,15 @@ impl<P: Player + Send + Sync> Controller<P> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[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 {
|
mod test_super {
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
use crate::{
|
use crate::{
|
||||||
config::config::tests::{new_config_lib, read_config_lib},
|
config::tests::{new_config_lib, read_config_lib},
|
||||||
music_storage::library,
|
music_storage::library,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -336,7 +336,7 @@ impl ITunesSong {
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::{path::{Path, PathBuf}, sync::{Arc, RwLock}};
|
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;
|
use super::ITunesLibrary;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use super::playlist::PlaylistFolder;
|
use super::playlist::PlaylistFolder;
|
||||||
// Crate things
|
// Crate things
|
||||||
use super::utils::{find_images, normalize, read_file, write_file};
|
use super::utils::{find_images, normalize, read_file, write_file};
|
||||||
use crate::config::config::Config;
|
use crate::config::Config;
|
||||||
|
|
||||||
// Various std things
|
// Various std things
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
@ -1127,7 +1127,7 @@ mod test {
|
||||||
sync::{Arc, RwLock},
|
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]
|
#[test]
|
||||||
fn library_init() {
|
fn library_init() {
|
||||||
|
|
|
@ -315,7 +315,7 @@ impl Default for Playlist {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_super {
|
mod test_super {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::config::config::tests::read_config_lib;
|
use crate::config::tests::read_config_lib;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_to_m3u8() {
|
fn list_to_m3u8() {
|
||||||
|
|
Loading…
Reference in a new issue