remove obsolete events and callbacks
This commit is contained in:
@@ -16,7 +16,6 @@ pub struct CommandManager {
|
||||
commands:
|
||||
HashMap<String, Box<dyn Fn(&mut Cursive, Vec<String>) -> Result<Option<String>, String>>>,
|
||||
aliases: HashMap<String, String>,
|
||||
callbacks: Vec<Box<dyn Fn() -> ()>>,
|
||||
}
|
||||
|
||||
impl CommandManager {
|
||||
@@ -24,7 +23,6 @@ impl CommandManager {
|
||||
CommandManager {
|
||||
commands: HashMap::new(),
|
||||
aliases: HashMap::new(),
|
||||
callbacks: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,14 +323,6 @@ impl CommandManager {
|
||||
v.set_error(e);
|
||||
});
|
||||
}
|
||||
|
||||
for cb in &self.callbacks {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register_callback(&mut self, cb: Box<dyn Fn() -> ()>) {
|
||||
self.callbacks.push(cb);
|
||||
}
|
||||
|
||||
pub fn register_keybinding<'a, E: Into<cursive::event::Event>, S: Into<String>>(
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
use crossbeam_channel::{unbounded, Receiver, Sender, TryIter};
|
||||
use cursive::{CbFunc, Cursive};
|
||||
|
||||
use playlists::PlaylistEvent;
|
||||
use spotify::PlayerEvent;
|
||||
|
||||
pub enum Event {
|
||||
Player(PlayerEvent),
|
||||
Playlist(PlaylistEvent),
|
||||
Command(String),
|
||||
ScreenChange(String),
|
||||
}
|
||||
|
||||
pub type EventSender = Sender<Event>;
|
||||
|
||||
@@ -126,7 +126,7 @@ fn main() {
|
||||
config::CLIENT_ID.to_string(),
|
||||
));
|
||||
|
||||
let queue = Arc::new(queue::Queue::new(event_manager.clone(), spotify.clone()));
|
||||
let queue = Arc::new(queue::Queue::new(spotify.clone()));
|
||||
|
||||
#[cfg(feature = "mpris")]
|
||||
let mpris_manager = Arc::new(mpris::MprisManager::new(spotify.clone(), queue.clone()));
|
||||
@@ -206,11 +206,9 @@ fn main() {
|
||||
#[cfg(feature = "mpris")]
|
||||
mpris_manager.update();
|
||||
}
|
||||
Event::Playlist(_event) => (),
|
||||
Event::Command(cmd) => {
|
||||
cmd_manager.handle(&mut cursive, cmd);
|
||||
}
|
||||
Event::ScreenChange(_name) => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::sync::{Arc, RwLock};
|
||||
|
||||
use rspotify::spotify::model::playlist::SimplifiedPlaylist;
|
||||
|
||||
use events::{Event, EventManager};
|
||||
use events::EventManager;
|
||||
use queue::Queue;
|
||||
use spotify::Spotify;
|
||||
use track::Track;
|
||||
@@ -16,10 +16,6 @@ pub struct Playlist {
|
||||
pub tracks: Vec<Track>,
|
||||
}
|
||||
|
||||
pub enum PlaylistEvent {
|
||||
NewList(usize, Playlist),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Playlists {
|
||||
pub store: Arc<RwLock<Vec<Playlist>>>,
|
||||
@@ -75,7 +71,7 @@ impl Playlists {
|
||||
store.extend(cache);
|
||||
|
||||
// force refresh of UI (if visible)
|
||||
self.ev.send(Event::ScreenChange("playlists".to_owned()));
|
||||
self.ev.trigger();
|
||||
}
|
||||
Err(e) => {
|
||||
error!("can't parse playlist cache: {}", e);
|
||||
@@ -154,11 +150,9 @@ impl Playlists {
|
||||
if self.needs_download(remote) {
|
||||
info!("updating playlist {}", remote.name);
|
||||
let playlist = Self::process_playlist(&remote, &self.spotify);
|
||||
let index = self.append_or_update(&playlist);
|
||||
self.ev.send(Event::Playlist(PlaylistEvent::NewList(
|
||||
index,
|
||||
playlist.clone(),
|
||||
)));
|
||||
self.append_or_update(&playlist);
|
||||
// trigger redraw
|
||||
self.ev.trigger();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use events::{Event, EventManager};
|
||||
use spotify::Spotify;
|
||||
use track::Track;
|
||||
|
||||
@@ -8,16 +7,14 @@ pub struct Queue {
|
||||
pub queue: Arc<RwLock<Vec<Track>>>,
|
||||
current_track: RwLock<Option<usize>>,
|
||||
spotify: Arc<Spotify>,
|
||||
ev: EventManager,
|
||||
}
|
||||
|
||||
impl Queue {
|
||||
pub fn new(ev: EventManager, spotify: Arc<Spotify>) -> Queue {
|
||||
pub fn new(spotify: Arc<Spotify>) -> Queue {
|
||||
Queue {
|
||||
queue: Arc::new(RwLock::new(Vec::new())),
|
||||
current_track: RwLock::new(None),
|
||||
spotify: spotify,
|
||||
ev: ev,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,9 +103,6 @@ impl Queue {
|
||||
|
||||
let mut q = self.queue.write().unwrap();
|
||||
q.clear();
|
||||
|
||||
// redraw queue if open
|
||||
self.ev.send(Event::ScreenChange("queue".to_owned()));
|
||||
}
|
||||
|
||||
pub fn play(&self, index: usize) {
|
||||
|
||||
@@ -178,7 +178,6 @@ impl View for Layout {
|
||||
// their items
|
||||
if self.screenchange {
|
||||
debug!("layout: new screen selected: {}", &id);
|
||||
self.ev.send(events::Event::ScreenChange(id.clone()));
|
||||
self.screenchange = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user