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 volnorm: Option<bool>,
pub volnorm_pregain: Option<f32>,
pub notify: Option<bool>
pub notify: Option<bool>,
}
#[derive(Serialize, Deserialize, Debug, Default, Clone)]

View File

@@ -224,10 +224,7 @@ fn main() {
&cfg,
));
let queue = Arc::new(queue::Queue::new(
spotify.clone(),
cfg.notify.unwrap_or(false),
));
let queue = Arc::new(queue::Queue::new(spotify.clone()));
#[cfg(feature = "mpris")]
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>>>,
current_track: RwLock<Option<usize>>,
repeat: RwLock<RepeatSetting>,
notify: bool,
spotify: Arc<Spotify>,
}
impl Queue {
pub fn new(spotify: Arc<Spotify>, notify: bool) -> Queue {
pub fn new(spotify: Arc<Spotify>) -> Queue {
let q = Queue {
queue: Arc::new(RwLock::new(Vec::new())),
spotify,
current_track: RwLock::new(None),
repeat: RwLock::new(RepeatSetting::None),
random_order: RwLock::new(None),
notify,
};
q.set_repeat(q.spotify.repeat);
q.set_shuffle(q.spotify.shuffle);
@@ -218,7 +216,7 @@ impl Queue {
let mut current = self.current_track.write().unwrap();
current.replace(index);
self.spotify.update_track();
if self.notify {
if self.spotify.cfg.notify.unwrap_or(false) {
Notification::new()
.summary(&track.to_string())
.show()

View File

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