Krolyxon
Commit 98cfe4e

rmptui98cfe4e

fix #3

Author
krolxon
Date
2024-05-12 20:37 +0530
Parent
8c4d19f
Commit
98cfe4eb264efd575ba0eaab7e6debe8ef8d40af

+19 −11

1 file changed

  1. M src/event/handler.rs +19 −11
M src/event/handler.rs View
@@ -58,18 +58,24 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
5858
5959 // Fast forward
6060 KeyCode::Char('f') => {
61− let place = app.conn.conn.status().unwrap().song.unwrap().pos;
62− let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
63− let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
64− app.conn.conn.seek(place, pos)?;
61+ if !app.queue_list.list.is_empty() {
62+ let status = app.conn.conn.status().unwrap_or_default();
63+ let place = status.song.unwrap_or_default().pos;
64+ let (pos, _) = status.time.unwrap_or_default();
65+ let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
66+ app.conn.conn.seek(place, pos)?;
67+ }
6568 }
6669
6770 // backward
6871 KeyCode::Char('b') => {
69− let place = app.conn.conn.status().unwrap().song.unwrap().pos;
70− let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
71− let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
72− app.conn.conn.seek(place, pos)?;
72+ if !app.queue_list.list.is_empty() {
73+ let status = app.conn.conn.status().unwrap_or_default();
74+ let place = status.song.unwrap_or_default().pos;
75+ let (pos, _) = status.time.unwrap_or_default();
76+ let pos = Duration::from_secs(pos.as_secs().wrapping_sub(2));
77+ app.conn.conn.seek(place, pos)?;
78+ }
7379 }
7480
7581 // Cycle through tabs
@@ -267,9 +273,11 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
267273 // add to current playlist
268274 KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right | KeyCode::Char(' ') => {
269275 // app.update_queue();
270− app.conn
271− .load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
272− app.conn.update_status();
276+ if !app.pl_list.list.is_empty() {
277+ app.conn
278+ .load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
279+ app.conn.update_status();
280+ }
273281 }
274282 _ => {}
275283 }