Add notifications
This commit is contained in:
committed by
Henrik Friedrichsen
parent
ea1856b312
commit
097f59eb83
@@ -19,6 +19,7 @@ pub struct Config {
|
||||
pub backend_device: Option<String>,
|
||||
pub volnorm: Option<bool>,
|
||||
pub volnorm_pregain: Option<f32>,
|
||||
pub notify: Option<bool>
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
|
||||
|
||||
@@ -224,7 +224,10 @@ fn main() {
|
||||
&cfg,
|
||||
));
|
||||
|
||||
let queue = Arc::new(queue::Queue::new(spotify.clone()));
|
||||
let queue = Arc::new(queue::Queue::new(
|
||||
spotify.clone(),
|
||||
cfg.notify.unwrap_or(false),
|
||||
));
|
||||
|
||||
#[cfg(feature = "mpris")]
|
||||
let mpris_manager = Arc::new(mpris::MprisManager::new(spotify.clone(), queue.clone()));
|
||||
|
||||
11
src/queue.rs
11
src/queue.rs
@@ -1,6 +1,7 @@
|
||||
use std::cmp::Ordering;
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use notify_rust::Notification;
|
||||
use rand::prelude::*;
|
||||
use strum_macros::Display;
|
||||
|
||||
@@ -19,17 +20,19 @@ 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>) -> Queue {
|
||||
pub fn new(spotify: Arc<Spotify>, notify: bool) -> 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);
|
||||
@@ -215,6 +218,12 @@ impl Queue {
|
||||
let mut current = self.current_track.write().unwrap();
|
||||
current.replace(index);
|
||||
self.spotify.update_track();
|
||||
if self.notify {
|
||||
Notification::new()
|
||||
.summary(&track.to_string())
|
||||
.show()
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
if reshuffle && self.get_shuffle() {
|
||||
|
||||
Reference in New Issue
Block a user