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