Add notifications
This commit is contained in:
committed by
Henrik Friedrichsen
parent
ea1856b312
commit
097f59eb83
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