fix #8
This commit is contained in:
parent
311cbc2631
commit
dc3f561de3
26
src/app.rs
26
src/app.rs
|
|
@ -30,6 +30,9 @@ pub struct App {
|
||||||
// used to show playlist popup
|
// used to show playlist popup
|
||||||
pub playlist_popup: bool,
|
pub playlist_popup: bool,
|
||||||
pub append_list: ContentList<String>,
|
pub append_list: ContentList<String>,
|
||||||
|
|
||||||
|
// Determines if the database should be updated or not
|
||||||
|
pub should_update_song_list: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
|
@ -67,12 +70,33 @@ impl App {
|
||||||
pl_cursor_pos: 0,
|
pl_cursor_pos: 0,
|
||||||
playlist_popup: false,
|
playlist_popup: false,
|
||||||
append_list,
|
append_list,
|
||||||
|
should_update_song_list: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tick(&mut self) {
|
pub fn tick(&mut self) -> AppResult<()> {
|
||||||
self.conn.update_status();
|
self.conn.update_status();
|
||||||
self.update_queue();
|
self.update_queue();
|
||||||
|
|
||||||
|
// Deals with database update
|
||||||
|
if self.should_update_song_list {
|
||||||
|
if let None = self.conn.status.updating_db {
|
||||||
|
// Update the songs list
|
||||||
|
self.conn.songs_filenames = self
|
||||||
|
.conn
|
||||||
|
.conn
|
||||||
|
.listall()?
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| x.file)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
self.browser.update_directory(&mut self.conn)?;
|
||||||
|
|
||||||
|
self.should_update_song_list = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn quit(&mut self) {
|
pub fn quit(&mut self) {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ pub struct Connection {
|
||||||
pub random: bool,
|
pub random: bool,
|
||||||
pub current_song: Song,
|
pub current_song: Song,
|
||||||
pub stats: mpd::Stats,
|
pub stats: mpd::Stats,
|
||||||
|
pub status: mpd::Status,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
|
|
@ -61,6 +62,7 @@ impl Connection {
|
||||||
random,
|
random,
|
||||||
current_song,
|
current_song,
|
||||||
stats,
|
stats,
|
||||||
|
status,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,6 +92,9 @@ impl Connection {
|
||||||
.unwrap_or(empty_song);
|
.unwrap_or(empty_song);
|
||||||
let stats = self.conn.stats().unwrap_or_default();
|
let stats = self.conn.stats().unwrap_or_default();
|
||||||
|
|
||||||
|
// Status
|
||||||
|
self.status = status.clone();
|
||||||
|
|
||||||
// Playback State
|
// Playback State
|
||||||
self.state = match status.state {
|
self.state = match status.state {
|
||||||
State::Stop => "Stopped".to_string(),
|
State::Stop => "Stopped".to_string(),
|
||||||
|
|
|
||||||
|
|
@ -141,17 +141,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
// Update MPD database
|
// Update MPD database
|
||||||
KeyCode::Char('U') => {
|
KeyCode::Char('U') => {
|
||||||
app.conn.conn.rescan()?;
|
app.conn.conn.rescan()?;
|
||||||
|
app.should_update_song_list = true;
|
||||||
// Update the songs list
|
|
||||||
app.conn.songs_filenames = app
|
|
||||||
.conn
|
|
||||||
.conn
|
|
||||||
.listall()?
|
|
||||||
.into_iter()
|
|
||||||
.map(|x| x.file)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
app.browser.update_directory(&mut app.conn)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search for songs
|
// Search for songs
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ fn main() -> AppResult<()> {
|
||||||
while app.running {
|
while app.running {
|
||||||
tui.draw(&mut app)?;
|
tui.draw(&mut app)?;
|
||||||
match tui.events.next()? {
|
match tui.events.next()? {
|
||||||
Event::Tick => app.tick(),
|
Event::Tick => app.tick()?,
|
||||||
Event::Key(key_event) => handler::handle_key_events(key_event, &mut app)?,
|
Event::Key(key_event) => handler::handle_key_events(key_event, &mut app)?,
|
||||||
Event::Mouse(_) => {}
|
Event::Mouse(_) => {}
|
||||||
Event::Resize(_, _) => {}
|
Event::Resize(_, _) => {}
|
||||||
|
|
|
||||||
Reference in New Issue