use cfg of spotify object

TODO:
- apply this to other single config values that are passed directly, e.g. in the
  statusbar
- use a more appropriate object to hold `cfg`
This commit is contained in:
Henrik Friedrichsen
2020-08-18 22:46:38 +02:00
parent cc2b1ae183
commit e5bc12b1ba
4 changed files with 5 additions and 10 deletions

View File

@@ -19,7 +19,7 @@ pub struct Config {
pub backend_device: Option<String>, pub backend_device: Option<String>,
pub volnorm: Option<bool>, pub volnorm: Option<bool>,
pub volnorm_pregain: Option<f32>, pub volnorm_pregain: Option<f32>,
pub notify: Option<bool> pub notify: Option<bool>,
} }
#[derive(Serialize, Deserialize, Debug, Default, Clone)] #[derive(Serialize, Deserialize, Debug, Default, Clone)]

View File

@@ -224,10 +224,7 @@ fn main() {
&cfg, &cfg,
)); ));
let queue = Arc::new(queue::Queue::new( let queue = Arc::new(queue::Queue::new(spotify.clone()));
spotify.clone(),
cfg.notify.unwrap_or(false),
));
#[cfg(feature = "mpris")] #[cfg(feature = "mpris")]
let mpris_manager = Arc::new(mpris::MprisManager::new(spotify.clone(), queue.clone())); let mpris_manager = Arc::new(mpris::MprisManager::new(spotify.clone(), queue.clone()));

View File

@@ -20,19 +20,17 @@ pub struct Queue {
random_order: RwLock<Option<Vec<usize>>>, random_order: RwLock<Option<Vec<usize>>>,
current_track: RwLock<Option<usize>>, current_track: RwLock<Option<usize>>,
repeat: RwLock<RepeatSetting>, repeat: RwLock<RepeatSetting>,
notify: bool,
spotify: Arc<Spotify>, spotify: Arc<Spotify>,
} }
impl Queue { impl Queue {
pub fn new(spotify: Arc<Spotify>, notify: bool) -> Queue { pub fn new(spotify: Arc<Spotify>) -> Queue {
let q = Queue { let q = Queue {
queue: Arc::new(RwLock::new(Vec::new())), queue: Arc::new(RwLock::new(Vec::new())),
spotify, spotify,
current_track: RwLock::new(None), current_track: RwLock::new(None),
repeat: RwLock::new(RepeatSetting::None), repeat: RwLock::new(RepeatSetting::None),
random_order: RwLock::new(None), random_order: RwLock::new(None),
notify,
}; };
q.set_repeat(q.spotify.repeat); q.set_repeat(q.spotify.repeat);
q.set_shuffle(q.spotify.shuffle); q.set_shuffle(q.spotify.shuffle);
@@ -218,7 +216,7 @@ impl Queue {
let mut current = self.current_track.write().unwrap(); let mut current = self.current_track.write().unwrap();
current.replace(index); current.replace(index);
self.spotify.update_track(); self.spotify.update_track();
if self.notify { if self.spotify.cfg.notify.unwrap_or(false) {
Notification::new() Notification::new()
.summary(&track.to_string()) .summary(&track.to_string())
.show() .show()

View File

@@ -83,7 +83,7 @@ pub enum PlayerEvent {
pub struct Spotify { pub struct Spotify {
events: EventManager, events: EventManager,
credentials: Credentials, credentials: Credentials,
cfg: config::Config, pub cfg: config::Config,
status: RwLock<PlayerEvent>, status: RwLock<PlayerEvent>,
api: RwLock<SpotifyAPI>, api: RwLock<SpotifyAPI>,
elapsed: RwLock<Option<Duration>>, elapsed: RwLock<Option<Duration>>,