Add notifications

This commit is contained in:
Ronak Buch
2020-08-18 22:38:15 +02:00
committed by Henrik Friedrichsen
parent ea1856b312
commit 097f59eb83
5 changed files with 130 additions and 2 deletions

View File

@@ -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() {