always trigger a cursive event when a queue event is generated

This commit is contained in:
Henrik Friedrichsen
2019-02-27 23:12:09 +01:00
parent d3c439342a
commit d73a3c144e
4 changed files with 12 additions and 12 deletions

View File

@@ -7,6 +7,7 @@ pub enum Event {
pub type EventSender = Sender<Event>; pub type EventSender = Sender<Event>;
#[derive(Clone)]
pub struct EventManager { pub struct EventManager {
tx: EventSender, tx: EventSender,
rx: Receiver<Event>, rx: Receiver<Event>,
@@ -28,8 +29,9 @@ impl EventManager {
self.rx.try_iter() self.rx.try_iter()
} }
pub fn sink(&mut self) -> EventSender { pub fn send(&self, event: Event) {
self.tx.clone() self.tx.send(event);
self.trigger();
} }
pub fn trigger(&self) { pub fn trigger(&self) {

View File

@@ -84,7 +84,7 @@ fn main() {
}; };
let cfg = config::load(path.to_str().unwrap()).expect("could not load configuration file"); let cfg = config::load(path.to_str().unwrap()).expect("could not load configuration file");
let queue = Arc::new(Mutex::new(queue::Queue::new(event_manager.sink()))); let queue = Arc::new(Mutex::new(queue::Queue::new(event_manager.clone())));
let spotify = Arc::new(spotify::Spotify::new( let spotify = Arc::new(spotify::Spotify::new(
cfg.username, cfg.username,
@@ -115,10 +115,10 @@ fn main() {
}); });
{ {
let event_sink = event_manager.sink(); let event_manager = event_manager.clone();
cursive.add_global_callback(Key::F2, move |s| { cursive.add_global_callback(Key::F2, move |s| {
s.set_screen(queuescreen); s.set_screen(queuescreen);
event_sink.send(Event::QueueUpdate); event_manager.clone().send(Event::QueueUpdate);
}); });
} }

View File

@@ -3,22 +3,22 @@ use std::collections::VecDeque;
use rspotify::spotify::model::track::FullTrack; use rspotify::spotify::model::track::FullTrack;
use events::{Event, EventSender}; use events::{Event, EventManager};
pub struct Queue { pub struct Queue {
queue: VecDeque<FullTrack>, queue: VecDeque<FullTrack>,
ev_sink: EventSender, ev: EventManager,
} }
impl Queue { impl Queue {
pub fn new(ev_sink: EventSender) -> Queue { pub fn new(ev: EventManager) -> Queue {
Queue { Queue {
queue: VecDeque::new(), queue: VecDeque::new(),
ev_sink: ev_sink, ev: ev,
} }
} }
fn send_event(&self) { fn send_event(&self) {
self.ev_sink.send(Event::QueueUpdate); self.ev.send(Event::QueueUpdate);
} }
pub fn remove(&mut self, index: usize) -> Option<FullTrack> { pub fn remove(&mut self, index: usize) -> Option<FullTrack> {
match self.queue.remove(index) { match self.queue.remove(index) {

View File

@@ -56,8 +56,6 @@ impl QueueView {
s.load(trackid); s.load(trackid);
s.play(); s.play();
queue_ref.lock().unwrap().remove(index); queue_ref.lock().unwrap().remove(index);
// TODO: update view representation, preferably, queue changes
// cause a view refresh
}); });
queuelist.add_child("", button); queuelist.add_child("", button);
} }